httpie-cli/httpie/compat.py

40 lines
1012 B
Python
Raw Normal View History

"""
Python 2.7, and 3.x compatibility.
"""
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
try: # pragma: no cover
# noinspection PyUnresolvedReferences,PyCompatibility
from urllib.parse import urlsplit
except ImportError: # pragma: no cover
# noinspection PyUnresolvedReferences,PyCompatibility
from urlparse import urlsplit
2014-04-24 14:07:31 +02:00
try: # pragma: no cover
# noinspection PyCompatibility
2014-04-24 14:07:31 +02:00
from urllib.request import urlopen
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