2013-01-03 16:12:27 +03:00
|
|
|
"""
|
2017-12-28 19:03:13 +02:00
|
|
|
Python 2.7, and 3.x compatibility.
|
2013-01-03 16:12:27 +03:00
|
|
|
|
|
|
|
"""
|
2015-02-24 08:39:26 +02:00
|
|
|
import sys
|
|
|
|
|
|
|
|
|
2015-02-24 09:18:03 +02: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 08:39:26 +02: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 08:39:26 +02:00
|
|
|
bytes = str
|
2016-07-04 20:30:55 +02:00
|
|
|
# noinspection PyUnresolvedReferences,PyShadowingBuiltins
|
2015-02-24 08:39:26 +02:00
|
|
|
str = unicode
|
|
|
|
elif is_py3:
|
2016-07-04 20:30:55 +02:00
|
|
|
# noinspection PyShadowingBuiltins
|
2015-02-24 08:39:26 +02:00
|
|
|
str = str
|
2016-07-04 20:30:55 +02:00
|
|
|
# noinspection PyShadowingBuiltins
|
2015-02-24 08:39:26 +02:00
|
|
|
bytes = bytes
|
|
|
|
|
2013-01-03 16:12:27 +03:00
|
|
|
|
2015-02-10 03:05:05 +02:00
|
|
|
try: # pragma: no cover
|
2015-01-23 23:04:42 +02:00
|
|
|
# noinspection PyUnresolvedReferences,PyCompatibility
|
2013-01-03 16:12:27 +03:00
|
|
|
from urllib.parse import urlsplit
|
2015-02-10 03:05:05 +02:00
|
|
|
except ImportError: # pragma: no cover
|
2015-01-23 23:04:42 +02:00
|
|
|
# noinspection PyUnresolvedReferences,PyCompatibility
|
2013-01-03 16:12:27 +03:00
|
|
|
from urlparse import urlsplit
|
2014-04-24 15:07:31 +03:00
|
|
|
|
2015-02-10 03:05:05 +02:00
|
|
|
try: # pragma: no cover
|
2015-01-23 23:04:42 +02:00
|
|
|
# noinspection PyCompatibility
|
2014-04-24 15:07:31 +03:00
|
|
|
from urllib.request import urlopen
|
2015-02-10 03:05:05 +02:00
|
|
|
except ImportError: # pragma: no cover
|
2016-07-04 20:30:55 +02:00
|
|
|
# noinspection PyCompatibility,PyUnresolvedReferences
|
2014-04-24 15:07:31 +03:00
|
|
|
from urllib2 import urlopen
|