##// END OF EJS Templates
Add module for Python 3 compatibility layer.
Thomas Kluyver -
Show More
@@ -0,0 +1,37 b''
1 import sys
2
3 def no_code(x, encoding=None):
4 return x
5
6 def decode(s, encoding=None):
7 encoding = encoding or sys.stdin.encoding or sys.getdefaultencoding()
8 return s.decode(encoding, "replace")
9
10 def encode(u, encoding=None):
11 encoding = encoding or sys.stdin.encoding or sys.getdefaultencoding()
12 return u.encode(encoding, "replace")
13
14 if sys.version_info[0] >= 3:
15 PY3 = True
16
17 input = input
18 builtin_mod_name = "builtins"
19
20 str_to_unicode = no_code
21 unicode_to_str = no_code
22 str_to_bytes = encode
23 bytes_to_str = decode
24
25 else:
26 PY3 = False
27
28 input = raw_input
29 builtin_mod_name = "__builtin__"
30
31 str_to_unicode = decode
32 unicode_to_str = encode
33 str_to_bytes = no_code
34 bytes_to_str = no_code
35
36 def execfile(fname, glob, loc):
37 exec compile(open(fname).read(), fname, 'exec') in glob, loc
General Comments 0
You need to be logged in to leave comments. Login now