compat.py — requests Source File
Architecture documentation for compat.py, a python file in the requests codebase. 12 imports, 10 dependents.
Entity Profile
Dependency Diagram
graph LR 655589d9_9504_8132_6277_d047dcd65486["compat.py"] 06d6d484_5fdf_93a9_a37e_3364cbf8b17e["importlib"] 655589d9_9504_8132_6277_d047dcd65486 --> 06d6d484_5fdf_93a9_a37e_3364cbf8b17e f748f9f7_0e4d_1e04_13aa_163d869167e7["sys"] 655589d9_9504_8132_6277_d047dcd65486 --> f748f9f7_0e4d_1e04_13aa_163d869167e7 46158510_6512_0701_6bee_d0295fbecfa8["urllib3"] 655589d9_9504_8132_6277_d047dcd65486 --> 46158510_6512_0701_6bee_d0295fbecfa8 92d49b68_807a_bbc1_04ef_f2d9531a4f96["simplejson"] 655589d9_9504_8132_6277_d047dcd65486 --> 92d49b68_807a_bbc1_04ef_f2d9531a4f96 bdbb7835_2516_c692_80a4_4e23b389849e["json"] 655589d9_9504_8132_6277_d047dcd65486 --> bdbb7835_2516_c692_80a4_4e23b389849e ccaec2dd_688f_da13_1759_2748abf12131["collections"] 655589d9_9504_8132_6277_d047dcd65486 --> ccaec2dd_688f_da13_1759_2748abf12131 d8c7b1a2_338b_d42b_f6c9_16b6072d856a["collections.abc"] 655589d9_9504_8132_6277_d047dcd65486 --> d8c7b1a2_338b_d42b_f6c9_16b6072d856a b3d61b15_e9e6_0a55_60b9_fd38c671809e["http"] 655589d9_9504_8132_6277_d047dcd65486 --> b3d61b15_e9e6_0a55_60b9_fd38c671809e 12b56a1b_bcad_a71c_0233_8ad1b8886587["http.cookies"] 655589d9_9504_8132_6277_d047dcd65486 --> 12b56a1b_bcad_a71c_0233_8ad1b8886587 b1946df2_c2d7_8311_fc51_9844255a3d78["io"] 655589d9_9504_8132_6277_d047dcd65486 --> b1946df2_c2d7_8311_fc51_9844255a3d78 7cade638_5d89_5696_c8fb_17ebadd07a56["urllib.parse"] 655589d9_9504_8132_6277_d047dcd65486 --> 7cade638_5d89_5696_c8fb_17ebadd07a56 3f16f8b4_95db_7097_4b74_e246a21c831f["urllib.request"] 655589d9_9504_8132_6277_d047dcd65486 --> 3f16f8b4_95db_7097_4b74_e246a21c831f ad9103ba_2c26_1ff0_c67d_e7f70c6f108c["_internal_utils.py"] ad9103ba_2c26_1ff0_c67d_e7f70c6f108c --> 655589d9_9504_8132_6277_d047dcd65486 8cafec3a_816a_3b74_357a_0167321e5d19["adapters.py"] 8cafec3a_816a_3b74_357a_0167321e5d19 --> 655589d9_9504_8132_6277_d047dcd65486 style 655589d9_9504_8132_6277_d047dcd65486 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""
requests.compat
~~~~~~~~~~~~~~~
This module previously handled import compatibility issues
between Python 2 and Python 3. It remains for backwards
compatibility until the next major version.
"""
import importlib
import sys
# -------
# urllib3
# -------
from urllib3 import __version__ as urllib3_version
# Detect which major version of urllib3 is being used.
try:
is_urllib3_1 = int(urllib3_version.split(".")[0]) == 1
except (TypeError, AttributeError):
# If we can't discern a version, prefer old functionality.
is_urllib3_1 = True
# -------------------
# Character Detection
# -------------------
def _resolve_char_detection():
"""Find supported character detection libraries."""
chardet = None
for lib in ("chardet", "charset_normalizer"):
if chardet is None:
try:
chardet = importlib.import_module(lib)
except ImportError:
pass
return chardet
chardet = _resolve_char_detection()
# -------
# Pythons
# -------
# Syntax sugar.
_ver = sys.version_info
#: Python 2.x?
is_py2 = _ver[0] == 2
#: Python 3.x?
is_py3 = _ver[0] == 3
# json/simplejson module import resolution
has_simplejson = False
try:
import simplejson as json
has_simplejson = True
except ImportError:
import json
if has_simplejson:
from simplejson import JSONDecodeError
else:
from json import JSONDecodeError
# Keep OrderedDict for backwards compatibility.
from collections import OrderedDict
from collections.abc import Callable, Mapping, MutableMapping
from http import cookiejar as cookielib
from http.cookies import Morsel
from io import StringIO
# --------------
# Legacy Imports
# --------------
from urllib.parse import (
quote,
quote_plus,
unquote,
unquote_plus,
urldefrag,
urlencode,
urljoin,
urlparse,
urlsplit,
urlunparse,
)
from urllib.request import (
getproxies,
getproxies_environment,
parse_http_list,
proxy_bypass,
proxy_bypass_environment,
)
builtin_str = str
str = str
bytes = bytes
basestring = (str, bytes)
numeric_types = (int, float)
integer_types = (int,)
Domain
Subdomains
Dependencies
- collections
- collections.abc
- http
- http.cookies
- importlib
- io
- json
- simplejson
- sys
- urllib.parse
- urllib.request
- urllib3
Imported By
Source
Frequently Asked Questions
What does compat.py do?
compat.py is a source file in the requests codebase, written in python. It belongs to the CoreAPI domain, VerbHandlers subdomain.
What functions are defined in compat.py?
compat.py defines 4 function(s): _resolve_char_detection, is_urllib3_1, json, simplejson.
What does compat.py depend on?
compat.py imports 12 module(s): collections, collections.abc, http, http.cookies, importlib, io, json, simplejson, and 4 more.
What files import compat.py?
compat.py is imported by 10 file(s): _internal_utils.py, adapters.py, auth.py, cookies.py, exceptions.py, models.py, packages.py, sessions.py, and 2 more.
Where is compat.py in the architecture?
compat.py is located at src/requests/compat.py (domain: CoreAPI, subdomain: VerbHandlers, directory: src/requests).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free