5
This module previously handled import compatibility issues
6
between Python 2 and Python 3. It remains for backwards
7
compatibility until the next major version.
10
# pyright: reportUnusedImport=false
12
from __future__ import annotations
16
from types import ModuleType
17
from typing import TYPE_CHECKING
22
from urllib3 import __version__ as urllib3_version
24
# Detect which major version of urllib3 is being used.
26
is_urllib3_1 = int(urllib3_version.split(".")[0]) == 1
27
except (TypeError, AttributeError):
28
# If we can't discern a version, prefer old functionality.
36
def _resolve_char_detection() -> ModuleType | None:
37
"""Find supported character detection libraries."""
39
for lib in ("chardet", "charset_normalizer"):
42
chardet = importlib.import_module(lib)
51
chardet = _resolve_char_detection()
58
_ver = sys.version_info
66
# json/simplejson module import resolution
69
import simplejson as json # type: ignore[import-not-found]
66
# json/simplejson module import resolution
69
import simplejson as json # type: ignore[import-not-found]
76
from simplejson import JSONDecodeError # type: ignore[import-not-found]
78
from json import JSONDecodeError
80
# Keep OrderedDict for backwards compatibility.
81
from collections import OrderedDict
82
from collections.abc import Callable, Mapping, MutableMapping
83
from http import cookiejar as cookielib
84
from http.cookies import Morsel
85
from io import StringIO
90
from urllib.parse import (
102
from urllib.request import (
104
getproxies_environment,
107
proxy_bypass_environment, # type: ignore[attr-defined] # https://github.com/python/cpython/issues/145331
113
basestring = (str, bytes)
114
numeric_types = (int, float)
115
integer_types = (int,)