1 # pylint: disable=unused-import,redefined-builtin,undefined-variable
2 from __future__
import absolute_import
, division
, unicode_literals
7 import urllib2
as parse
# noqa
10 from urllib
import parse
# noqa
13 PY2
= sys
.version_info
[0] == 2
14 PY3
= sys
.version_info
[0] >= 3
15 PY26_PLUS
= PY2
and sys
.version_info
[1] >= 6
16 WIN32
= sys
.platform
== 'win32' or sys
.platform
== 'cygwin'
22 def bstr(x
, encoding
=ENCODING
):
23 return bytes(x
, encoding
=encoding
)
44 # pylint: disable=unicode-builtin
46 # pylint: disable=unichr-builtin
48 # pylint: disable=long-builtin
49 int_types
= (int, long) # noqa
51 # Qt's max 32-bit signed integer range (-2147483648 to 2147483647)
52 maxint
= (2 ** 31) - 1
55 def setenv(key
, value
):
56 """Compatibility wrapper for setting environment variables
58 Why? win32 requires putenv(). UNIX only requires os.environ.
61 if not PY3
and isinstance(value
, ustr
):
62 value
= value
.encode(ENCODING
, 'replace')
63 os
.environ
[key
] = value
68 """Compatibility wrapper for unsetting environment variables"""
69 os
.environ
.pop(key
, None)
70 if hasattr(os
, 'unsetenv'):
75 """Return the value as-is"""
79 def byte_offset_to_int_converter():
80 """Return a function to convert byte string offsets into ints
82 Indexing into python3 bytes returns ints, Python2 returns str.
83 Thus, on Python2 we need to use `ord()` to convert the byte into
84 an integration. It's already an int on Python3, so we use no_op there.