From 19346fa9068878af516cdb670bea4f791337507b Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Sun, 29 Sep 2013 05:12:56 -0400 Subject: Initial commit --- simplejson/compat.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 simplejson/compat.py (limited to 'simplejson/compat.py') diff --git a/simplejson/compat.py b/simplejson/compat.py new file mode 100644 index 0000000..449e48a --- /dev/null +++ b/simplejson/compat.py @@ -0,0 +1,43 @@ +"""Python 3 compatibility shims +""" +import sys +if sys.version_info[0] < 3: + PY3 = False + def b(s): + return s + def u(s): + return unicode(s, 'unicode_escape') + import cStringIO as StringIO + StringIO = BytesIO = StringIO.StringIO + text_type = unicode + binary_type = str + string_types = (basestring,) + integer_types = (int, long) + unichr = unichr + reload_module = reload + def fromhex(s): + return s.decode('hex') + +else: + PY3 = True + from imp import reload as reload_module + import codecs + def b(s): + return codecs.latin_1_encode(s)[0] + def u(s): + return s + import io + StringIO = io.StringIO + BytesIO = io.BytesIO + text_type = str + binary_type = bytes + string_types = (str,) + integer_types = (int,) + + def unichr(s): + return u(chr(s)) + + def fromhex(s): + return bytes.fromhex(s) + +long_type = integer_types[-1] -- cgit v1.2.3-70-g09d2