Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(209)

Side by Side Diff: third_party/requests/compat.py

Issue 24076010: Add 'requests' library to third_party. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/swarm_client
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 # -*- coding: utf-8 -*-
2
3 """
4 pythoncompat
5 """
6
7 from .packages import charade as 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 #: Python 3.0.x
25 is_py30 = (is_py3 and _ver[1] == 0)
26
27 #: Python 3.1.x
28 is_py31 = (is_py3 and _ver[1] == 1)
29
30 #: Python 3.2.x
31 is_py32 = (is_py3 and _ver[1] == 2)
32
33 #: Python 3.3.x
34 is_py33 = (is_py3 and _ver[1] == 3)
35
36 #: Python 3.4.x
37 is_py34 = (is_py3 and _ver[1] == 4)
38
39 #: Python 2.7.x
40 is_py27 = (is_py2 and _ver[1] == 7)
41
42 #: Python 2.6.x
43 is_py26 = (is_py2 and _ver[1] == 6)
44
45 #: Python 2.5.x
46 is_py25 = (is_py2 and _ver[1] == 5)
47
48 #: Python 2.4.x
49 is_py24 = (is_py2 and _ver[1] == 4) # I'm assuming this is not by choice.
50
51
52 # ---------
53 # Platforms
54 # ---------
55
56
57 # Syntax sugar.
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 # Assume CPython, if nothing else.
65 is_cpython = not any((is_pypy, is_jython, is_ironpython))
66
67 # Windows-based system.
68 is_windows = 'win32' in str(sys.platform).lower()
69
70 # Standard Linux 2+ system.
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()) # Complete guess.
74 is_solaris = ('solar==' in str(sys.platform).lower()) # Complete guess.
75
76 try:
77 import simplejson as json
78 except ImportError:
79 import json
80
81 # ---------
82 # Specifics
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)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698