| 1 |
|
| 2 |
|
| 3 |
""" |
| 4 |
pythoncompat |
| 5 |
""" |
| 6 |
|
| 7 |
from .packages import charade as chardet |
| 8 |
|
| 9 |
import sys |
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
_ver = sys.version_info |
| 17 |
|
| 18 |
|
| 19 |
is_py2 = (_ver[0] == 2) |
| 20 |
|
| 21 |
|
| 22 |
is_py3 = (_ver[0] == 3) |
| 23 |
|
| 24 |
|
| 25 |
is_py30 = (is_py3 and _ver[1] == 0) |
| 26 |
|
| 27 |
|
| 28 |
is_py31 = (is_py3 and _ver[1] == 1) |
| 29 |
|
| 30 |
|
| 31 |
is_py32 = (is_py3 and _ver[1] == 2) |
| 32 |
|
| 33 |
|
| 34 |
is_py33 = (is_py3 and _ver[1] == 3) |
| 35 |
|
| 36 |
|
| 37 |
is_py34 = (is_py3 and _ver[1] == 4) |
| 38 |
|
| 39 |
|
| 40 |
is_py27 = (is_py2 and _ver[1] == 7) |
| 41 |
|
| 42 |
|
| 43 |
is_py26 = (is_py2 and _ver[1] == 6) |
| 44 |
|
| 45 |
|
| 46 |
is_py25 = (is_py2 and _ver[1] == 5) |
| 47 |
|
| 48 |
|
| 49 |
is_py24 = (is_py2 and _ver[1] == 4) |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
_ver = sys.version.lower() |
| 59 |
|
| 60 |
is_pypy = ('pypy' in _ver) |
| 61 |
is_jython = ('jython' in _ver) |
| 62 |
is_ironpython = ('iron' in _ver) |
| 63 |
|
| 64 |
|
| 65 |
is_cpython = not any((is_pypy, is_jython, is_ironpython)) |
| 66 |
|
| 67 |
|
| 68 |
is_windows = 'win32' in str(sys.platform).lower() |
| 69 |
|
| 70 |
|
| 71 |
is_linux = ('linux' in str(sys.platform).lower()) |
| 72 |
is_osx = ('darwin' in str(sys.platform).lower()) |
| 73 |
is_hpux = ('hpux' in str(sys.platform).lower()) |
| 74 |
is_solaris = ('solar==' in str(sys.platform).lower()) |
| 75 |
|
| 76 |
try: |
| 77 |
import simplejson as json |
| 78 |
except ImportError: |
| 79 |
import json |
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
if is_py2: |
| 86 |
from urllib import quote, unquote, quote_plus, unquote_plus, urlencode |
| 87 |
from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag |
| 88 |
from urllib2 import parse_http_list |
| 89 |
import cookielib |
| 90 |
from Cookie import Morsel |
| 91 |
from StringIO import StringIO |
| 92 |
from .packages.urllib3.packages.ordered_dict import OrderedDict |
| 93 |
|
| 94 |
builtin_str = str |
| 95 |
bytes = str |
| 96 |
str = unicode |
| 97 |
basestring = basestring |
| 98 |
numeric_types = (int, long, float) |
| 99 |
|
| 100 |
|
| 101 |
elif is_py3: |
| 102 |
from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag |
| 103 |
from urllib.request import parse_http_list |
| 104 |
from http import cookiejar as cookielib |
| 105 |
from http.cookies import Morsel |
| 106 |
from io import StringIO |
| 107 |
from collections import OrderedDict |
| 108 |
|
| 109 |
builtin_str = str |
| 110 |
str = str |
| 111 |
bytes = bytes |
| 112 |
basestring = (str, bytes) |
| 113 |
numeric_types = (int, float) |