1"""
2requests.compat
3~~~~~~~~~~~~~~~
4
5This module previously handled import compatibility issues
6between Python 2 and Python 3. It remains for backwards
7compatibility until the next major version.
8"""
9
10# pyright: reportUnusedImport=false
11
12from __future__ import annotations
13
14import sys
15
16# -------
17# urllib3
18# -------
19from pip._vendor.urllib3 import (
20 __version__ as urllib3_version, # type: ignore[reportPrivateImportUsage]
21)
22
23# Detect which major version of urllib3 is being used.
24try:
25 is_urllib3_1 = int(urllib3_version.split(".")[0]) == 1
26except (TypeError, AttributeError):
27 # If we can't discern a version, prefer old functionality.
28 is_urllib3_1 = True
29
30# -------------------
31# Character Detection
32# -------------------
33
34
35def _resolve_char_detection() -> None:
36 """Find supported character detection libraries."""
37 chardet = None
38 return chardet
39
40
41chardet = _resolve_char_detection()
42
43# -------
44# Pythons
45# -------
46
47# Syntax sugar.
48_ver = sys.version_info
49
50#: Python 2.x?
51is_py2 = _ver[0] == 2
52
53#: Python 3.x?
54is_py3 = _ver[0] == 3
55
56# Note: We've patched out simplejson support in pip because it prevents
57# upgrading simplejson on Windows.
58import json
59from json import JSONDecodeError
60
61# Keep OrderedDict for backwards compatibility.
62from collections import OrderedDict
63from collections.abc import Callable, Mapping, MutableMapping
64from http import cookiejar as cookielib
65from http.cookies import Morsel
66from io import StringIO
67
68# --------------
69# Legacy Imports
70# --------------
71from urllib.parse import (
72 quote,
73 quote_plus,
74 unquote,
75 unquote_plus,
76 urldefrag,
77 urlencode,
78 urljoin,
79 urlparse,
80 urlsplit,
81 urlunparse,
82)
83from urllib.request import (
84 getproxies,
85 getproxies_environment,
86 parse_http_list,
87 proxy_bypass,
88 proxy_bypass_environment, # type: ignore[attr-defined] # https://github.com/python/cpython/issues/145331
89)
90
91builtin_str = str
92str = str
93bytes = bytes
94basestring = (str, bytes)
95numeric_types = (int, float)
96integer_types = (int,)