5 import urllib2
as parse
# noqa
8 from urllib
import parse
# noqa
11 PY_VERSION
= sys
.version_info
[:2] # (2, 7)
12 PY_VERSION_MAJOR
= PY_VERSION
[0]
13 PY2
= PY_VERSION_MAJOR
== 2
14 PY3
= PY_VERSION_MAJOR
>= 3
15 PY26_PLUS
= PY2
and sys
.version_info
[1] >= 6
16 WIN32
= sys
.platform
in {'win32', 'cygwin'}
22 def bstr(value
, encoding
=ENCODING
):
23 return bytes(value
, encoding
=encoding
)
46 int_types
= (int, long) # noqa
48 # The max 32-bit signed integer range for Qt is (-2147483648 to 2147483647)
52 def setenv(key
, value
):
53 """Compatibility wrapper for setting environment variables
55 Windows requires putenv(). Unix only requires os.environ.
57 if not PY3
and isinstance(value
, ustr
):
58 value
= value
.encode(ENCODING
, 'replace')
59 os
.environ
[key
] = value
64 """Compatibility wrapper for clearing environment variables"""
65 os
.environ
.pop(key
, None)
66 if hasattr(os
, 'unsetenv'):
71 """Return the value as-is"""
75 def byte_offset_to_int_converter():
76 """Return a function to convert byte string offsets into integers
78 Indexing into python3 bytes returns integers. Python2 returns str.
79 Thus, on Python2 we need to use `ord()` to convert the byte into
80 an integer. It's already an int on Python3, so we use no_op there.