2016-01-31 14:44:46 +00:00
|
|
|
"""Python 3 compatibility shims
|
|
|
|
"""
|
|
|
|
import sys
|
|
|
|
if sys.version_info[0] < 3:
|
|
|
|
PY3 = False
|
|
|
|
def b(s):
|
|
|
|
return s
|
2019-01-20 10:35:31 +00:00
|
|
|
try:
|
|
|
|
from cStringIO import StringIO
|
|
|
|
except ImportError:
|
|
|
|
from StringIO import StringIO
|
|
|
|
BytesIO = StringIO
|
2016-01-31 14:44:46 +00:00
|
|
|
text_type = unicode
|
|
|
|
binary_type = str
|
|
|
|
string_types = (basestring,)
|
|
|
|
integer_types = (int, long)
|
|
|
|
unichr = unichr
|
|
|
|
reload_module = reload
|
|
|
|
else:
|
|
|
|
PY3 = True
|
|
|
|
if sys.version_info[:2] >= (3, 4):
|
|
|
|
from importlib import reload as reload_module
|
|
|
|
else:
|
|
|
|
from imp import reload as reload_module
|
|
|
|
def b(s):
|
2019-01-20 10:35:31 +00:00
|
|
|
return bytes(s, 'latin1')
|
|
|
|
from io import StringIO, BytesIO
|
2016-01-31 14:44:46 +00:00
|
|
|
text_type = str
|
|
|
|
binary_type = bytes
|
|
|
|
string_types = (str,)
|
|
|
|
integer_types = (int,)
|
2019-01-20 10:35:31 +00:00
|
|
|
unichr = chr
|
2016-01-31 14:44:46 +00:00
|
|
|
|
|
|
|
long_type = integer_types[-1]
|