Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/requests/compat.py: 95%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2requests.compat
3~~~~~~~~~~~~~~~
5This module previously handled import compatibility issues
6between Python 2 and Python 3. It remains for backwards
7compatibility until the next major version.
8"""
10import importlib
11import sys
13# -------------------
14# Character Detection
15# -------------------
18def _resolve_char_detection():
19 """Find supported character detection libraries."""
20 chardet = None
21 for lib in ("chardet", "charset_normalizer"):
22 if chardet is None:
23 try:
24 chardet = importlib.import_module(lib)
25 except ImportError:
26 pass
27 return chardet
30chardet = _resolve_char_detection()
32# -------
33# Pythons
34# -------
36# Syntax sugar.
37_ver = sys.version_info
39#: Python 2.x?
40is_py2 = _ver[0] == 2
42#: Python 3.x?
43is_py3 = _ver[0] == 3
45# json/simplejson module import resolution
46has_simplejson = False
47try:
48 import simplejson as json
50 has_simplejson = True
51except ImportError:
52 import json
54if has_simplejson:
55 from simplejson import JSONDecodeError
56else:
57 from json import JSONDecodeError
59# Keep OrderedDict for backwards compatibility.
60from collections import OrderedDict
61from collections.abc import Callable, Mapping, MutableMapping
62from http import cookiejar as cookielib
63from http.cookies import Morsel
64from io import StringIO
66# --------------
67# Legacy Imports
68# --------------
69from urllib.parse import (
70 quote,
71 quote_plus,
72 unquote,
73 unquote_plus,
74 urldefrag,
75 urlencode,
76 urljoin,
77 urlparse,
78 urlsplit,
79 urlunparse,
80)
81from urllib.request import (
82 getproxies,
83 getproxies_environment,
84 parse_http_list,
85 proxy_bypass,
86 proxy_bypass_environment,
87)
89builtin_str = str
90str = str
91bytes = bytes
92basestring = (str, bytes)
93numeric_types = (int, float)
94integer_types = (int,)