1 # pylint: disable=unused-import,redefined-builtin,undefined-variable
2 from __future__
import absolute_import
, division
, unicode_literals
6 import urllib2
as parse
# noqa
9 from urllib
import parse
# noqa
12 PY2
= sys
.version_info
[0] == 2
13 PY3
= sys
.version_info
[0] >= 3
14 PY26_PLUS
= PY2
and sys
.version_info
[1] >= 6
15 WIN32
= sys
.platform
== 'win32' or sys
.platform
== 'cygwin'
20 def bstr(x
, encoding
=ENCODING
):
21 return bytes(x
, encoding
=encoding
)
40 # pylint: disable=unicode-builtin
42 # pylint: disable=unichr-builtin
44 # pylint: disable=long-builtin
45 int_types
= (int, long) # noqa
48 def setenv(key
, value
):
49 """Compatibility wrapper for setting environment variables
51 Why? win32 requires putenv(). UNIX only requires os.environ.
54 if not PY3
and isinstance(value
, ustr
):
55 value
= value
.encode(ENCODING
, 'replace')
56 os
.environ
[key
] = value
61 """Compatibility wrapper for unsetting environment variables"""
62 os
.environ
.pop(key
, None)
63 if hasattr(os
, 'unsetenv'):
68 """Return the value as-is"""
72 def byte_offset_to_int_converter():
73 """Return a function to convert byte string offsets into ints
75 Indexing into python3 bytes returns ints, Python2 returns str.
76 Thus, on Python2 we need to use `ord()` to convert the byte into
77 an integration. It's already an int on Python3, so we use no_op there.