1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
"""Python 3 compatibility shims
"""
import os
import sys
import codecs
if sys.version_info[0] < 3:
integer_types = (int, long)
text_type = unicode
binary_type = str
else:
integer_types = (int,)
text_type = str
binary_type = bytes
fs_encoding = sys.getfilesystemencoding()
fs_errors = 'strict'
if fs_encoding != 'mbcs':
try:
codecs.lookup('surrogateescape')
fs_errors = 'surrogateescape'
except LookupError:
pass
try:
fs_encode = os.fsencode
except AttributeError:
def fs_encode(val):
if not isinstance(val, bytes):
return val.encode(fs_encoding, fs_errors)
else:
return val
|