Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/requests/compat.py: 91%
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# urllib3
15# -------
16from urllib3 import __version__ as urllib3_version
18# Detect which major version of urllib3 is being used.
19try:
20 is_urllib3_1 = int(urllib3_version.split(".")[0]) == 1
21except (TypeError, AttributeError):
22 # If we can't discern a version, prefer old functionality.
23 is_urllib3_1 = True
25# -------------------
26# Character Detection
27# -------------------
30def _resolve_char_detection():
31 """Find supported character detection libraries."""
32 chardet = None
33 for lib in ("chardet", "charset_normalizer"):
34 if chardet is None:
35 try:
36 chardet = importlib.import_module(lib)
37 except ImportError:
38 pass
39 return chardet
42chardet = _resolve_char_detection()
44# -------
45# Pythons
46# -------
48# Syntax sugar.
49_ver = sys.version_info
51#: Python 2.x?
52is_py2 = _ver[0] == 2
54#: Python 3.x?
55is_py3 = _ver[0] == 3
57# json/simplejson module import resolution
58has_simplejson = False
59try:
60 import simplejson as json
62 has_simplejson = True
63except ImportError:
64 import json
66if has_simplejson:
67 from simplejson import JSONDecodeError
68else:
69 from json import JSONDecodeError
71# Keep OrderedDict for backwards compatibility.
72from collections import OrderedDict
73from collections.abc import Callable, Mapping, MutableMapping
74from http import cookiejar as cookielib
75from http.cookies import Morsel
76from io import StringIO
78# --------------
79# Legacy Imports
80# --------------
81from urllib.parse import (
82 quote,
83 quote_plus,
84 unquote,
85 unquote_plus,
86 urldefrag,
87 urlencode,
88 urljoin,
89 urlparse,
90 urlsplit,
91 urlunparse,
92)
93from urllib.request import (
94 getproxies,
95 getproxies_environment,
96 parse_http_list,
97 proxy_bypass,
98 proxy_bypass_environment,
99)
101builtin_str = str
102str = str
103bytes = bytes
104basestring = (str, bytes)
105numeric_types = (int, float)
106integer_types = (int,)