diff options
author | Alex Grönholm <alex.gronholm+git@nextday.fi> | 2012-08-07 00:15:53 +0300 |
---|---|---|
committer | Alex Grönholm <alex.gronholm+git@nextday.fi> | 2012-08-07 00:15:53 +0300 |
commit | 0aaa404f3525641fe5bb3b50ca303d05a326cdce (patch) | |
tree | cd9bb0d8c37b01a98a5a3891891061605d4c30e2 /redis/_compat.py | |
parent | 826364f3bb19abca0e1e6a92266abb017f5481f4 (diff) | |
download | redis-py-0aaa404f3525641fe5bb3b50ca303d05a326cdce.tar.gz |
Fixed Python 3.2+ compatibility
Diffstat (limited to 'redis/_compat.py')
-rw-r--r-- | redis/_compat.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/redis/_compat.py b/redis/_compat.py new file mode 100644 index 0000000..2dbf62e --- /dev/null +++ b/redis/_compat.py @@ -0,0 +1,48 @@ +"""Internal module for Python 2 backwards compatibility.""" +import sys + + +if sys.version_info[0] < 3: + from urlparse import urlparse + from itertools import imap, izip + from string import letters as ascii_letters + try: + from cStringIO import StringIO as BytesIO + except ImportError: + from StringIO import StringIO as BytesIO + + iteritems = lambda x: x.iteritems() + dictkeys = lambda x: x.keys() + dictvalues = lambda x: x.values() + nativestr = lambda x: x if isinstance(x, str) else x.encode(errors='replace') + u = lambda x: x.decode() + b = lambda x: x + next = lambda x: x.next() + byte_to_chr = lambda x: x + unichr = unichr + xrange = xrange + basestring = basestring + unicode = unicode + bytes = str + long = long +else: + from urllib.parse import urlparse + from io import BytesIO + from string import ascii_letters + + iteritems = lambda x: x.items() + dictkeys = lambda x: list(x.keys()) + dictvalues = lambda x: list(x.values()) + byte_to_chr = lambda x: chr(x) + nativestr = lambda x: x if isinstance(x, str) else x.decode(errors='replace') + u = lambda x: x + b = lambda x: x.encode('iso-8859-1') + next = next + unichr = chr + imap = map + izip = zip + xrange = range + basestring = str + unicode = str + bytes = bytes + long = int |