a0af4a1cb86e070ca42b45ac5c7cd1eca3619c79
[wikipedia-api-cdsw] / simplejson / compat.py
1 """Python 3 compatibility shims
2 """
3 import sys
4 if sys.version_info[0] < 3:
5     PY3 = False
6     def b(s):
7         return s
8     def u(s):
9         return unicode(s, 'unicode_escape')
10     import cStringIO as StringIO
11     StringIO = BytesIO = StringIO.StringIO
12     text_type = unicode
13     binary_type = str
14     string_types = (basestring,)
15     integer_types = (int, long)
16     unichr = unichr
17     reload_module = reload
18     def fromhex(s):
19         return s.decode('hex')
20
21 else:
22     PY3 = True
23     if sys.version_info[:2] >= (3, 4):
24         from importlib import reload as reload_module
25     else:
26         from imp import reload as reload_module
27     import codecs
28     def b(s):
29         return codecs.latin_1_encode(s)[0]
30     def u(s):
31         return s
32     import io
33     StringIO = io.StringIO
34     BytesIO = io.BytesIO
35     text_type = str
36     binary_type = bytes
37     string_types = (str,)
38     integer_types = (int,)
39
40     def unichr(s):
41         return u(chr(s))
42
43     def fromhex(s):
44         return bytes.fromhex(s)
45
46 long_type = integer_types[-1]

Benjamin Mako Hill || Want to submit a patch?