1 """Internal module for Python 2 backwards compatibility."""
2 import sys
3
4
5 if sys.version_info[0] < 3:
6 from urlparse import urlparse
7 from itertools import imap, izip
8 from string import letters as ascii_letters
9 try:
10 from cStringIO import StringIO as BytesIO
11 except ImportError:
12 from StringIO import StringIO as BytesIO
13
14 iteritems = lambda x: x.iteritems()
15 dictkeys = lambda x: x.keys()
16 dictvalues = lambda x: x.values()
17 nativestr = lambda x: \
18 x if isinstance(x, str) else x.encode('utf-8', 'replace')
19 u = lambda x: x.decode()
20 b = lambda x: x
21 next = lambda x: x.next()
22 byte_to_chr = lambda x: x
23 unichr = unichr
24 xrange = xrange
25 basestring = basestring
26 unicode = unicode
27 bytes = str
28 long = long
29 else:
30 from urllib.parse import urlparse
31 from io import BytesIO
32 from string import ascii_letters
33
34 iteritems = lambda x: x.items()
35 dictkeys = lambda x: list(x.keys())
36 dictvalues = lambda x: list(x.values())
37 byte_to_chr = lambda x: chr(x)
38 nativestr = lambda x: \
39 x if isinstance(x, str) else x.decode('utf-8', 'replace')
40 u = lambda x: x
41 b = lambda x: x.encode('iso-8859-1')
42 next = next
43 unichr = chr
44 imap = map
45 izip = zip
46 xrange = range
47 basestring = str
48 unicode = str
49 bytes = bytes
50 long = int
51