2013-01-03 14:12:27 +01:00
|
|
|
"""
|
2017-12-28 18:03:13 +01:00
|
|
|
Python 2.7, and 3.x compatibility.
|
2013-01-03 14:12:27 +01:00
|
|
|
|
|
|
|
"""
|
2015-02-24 07:39:26 +01:00
|
|
|
import sys
|
|
|
|
|
|
|
|
|
2015-02-24 08:18:03 +01:00
|
|
|
is_py2 = sys.version_info[0] == 2
|
|
|
|
is_py27 = sys.version_info[:2] == (2, 7)
|
|
|
|
is_py3 = sys.version_info[0] == 3
|
|
|
|
is_pypy = 'pypy' in sys.version.lower()
|
2015-02-24 07:39:26 +01:00
|
|
|
is_windows = 'win32' in str(sys.platform).lower()
|
|
|
|
|
|
|
|
|
|
|
|
if is_py2:
|
2016-07-04 20:30:55 +02:00
|
|
|
# noinspection PyShadowingBuiltins
|
2015-02-24 07:39:26 +01:00
|
|
|
bytes = str
|
2016-07-04 20:30:55 +02:00
|
|
|
# noinspection PyUnresolvedReferences,PyShadowingBuiltins
|
2015-02-24 07:39:26 +01:00
|
|
|
str = unicode
|
|
|
|
elif is_py3:
|
2016-07-04 20:30:55 +02:00
|
|
|
# noinspection PyShadowingBuiltins
|
2015-02-24 07:39:26 +01:00
|
|
|
str = str
|
2016-07-04 20:30:55 +02:00
|
|
|
# noinspection PyShadowingBuiltins
|
2015-02-24 07:39:26 +01:00
|
|
|
bytes = bytes
|
|
|
|
|
2013-01-03 14:12:27 +01:00
|
|
|
|
2015-02-10 02:05:05 +01:00
|
|
|
try: # pragma: no cover
|
2015-01-23 22:04:42 +01:00
|
|
|
# noinspection PyUnresolvedReferences,PyCompatibility
|
2013-01-03 14:12:27 +01:00
|
|
|
from urllib.parse import urlsplit
|
2015-02-10 02:05:05 +01:00
|
|
|
except ImportError: # pragma: no cover
|
2015-01-23 22:04:42 +01:00
|
|
|
# noinspection PyUnresolvedReferences,PyCompatibility
|
2013-01-03 14:12:27 +01:00
|
|
|
from urlparse import urlsplit
|
2014-04-24 14:07:31 +02:00
|
|
|
|
2015-02-10 02:05:05 +01:00
|
|
|
try: # pragma: no cover
|
2015-01-23 22:04:42 +01:00
|
|
|
# noinspection PyCompatibility
|
2014-04-24 14:07:31 +02:00
|
|
|
from urllib.request import urlopen
|
2015-02-10 02:05:05 +01:00
|
|
|
except ImportError: # pragma: no cover
|
2016-07-04 20:30:55 +02:00
|
|
|
# noinspection PyCompatibility,PyUnresolvedReferences
|
2014-04-24 14:07:31 +02:00
|
|
|
from urllib2 import urlopen
|