summaryrefslogtreecommitdiff
path: root/simplejson/compat.py
diff options
context:
space:
mode:
authorBob Ippolito <bob@redivi.com>2012-12-26 12:48:47 -0800
committerBob Ippolito <bob@redivi.com>2012-12-28 11:03:45 -0800
commit5846148410234f6466aefcddc68683811577998e (patch)
tree27af6427a02a0c995ea382c029027674e1031a2f /simplejson/compat.py
parent57d980277f8d1d6324904edd43e1a730572b64b6 (diff)
downloadsimplejson-5846148410234f6466aefcddc68683811577998e.tar.gz
First pass at Python 3.3 compatibility
First pass at Python 3.3 compatibility, bump to 3.0.0
Diffstat (limited to 'simplejson/compat.py')
-rw-r--r--simplejson/compat.py43
1 files changed, 43 insertions, 0 deletions
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]