70edff784951c903d89c48697ac77e08759a3098
[sdc/sdc-distribution-client.git] /
1 # -*- coding: utf-8 -*-
2
3 """
4 pythoncompat
5 """
6
7 from .packages import chardet
8
9 import sys
10
11 # -------
12 # Pythons
13 # -------
14
15 # Syntax sugar.
16 _ver = sys.version_info
17
18 #: Python 2.x?
19 is_py2 = (_ver[0] == 2)
20
21 #: Python 3.x?
22 is_py3 = (_ver[0] == 3)
23
24 try:
25     import simplejson as json
26 except (ImportError, SyntaxError):
27     # simplejson does not support Python 3.2, it throws a SyntaxError
28     # because of u'...' Unicode literals.
29     import json
30
31 # ---------
32 # Specifics
33 # ---------
34
35 if is_py2:
36     from urllib import quote, unquote, quote_plus, unquote_plus, urlencode, getproxies, proxy_bypass
37     from urlparse import urlparse, urlunparse, urljoin, urlsplit, urldefrag
38     from urllib2 import parse_http_list
39     import cookielib
40     from Cookie import Morsel
41     from StringIO import StringIO
42     from .packages.urllib3.packages.ordered_dict import OrderedDict
43
44     builtin_str = str
45     bytes = str
46     str = unicode
47     basestring = basestring
48     numeric_types = (int, long, float)
49
50 elif is_py3:
51     from urllib.parse import urlparse, urlunparse, urljoin, urlsplit, urlencode, quote, unquote, quote_plus, unquote_plus, urldefrag
52     from urllib.request import parse_http_list, getproxies, proxy_bypass
53     from http import cookiejar as cookielib
54     from http.cookies import Morsel
55     from io import StringIO
56     from collections import OrderedDict
57
58     builtin_str = str
59     str = str
60     bytes = bytes
61     basestring = (str, bytes)
62     numeric_types = (int, float)