1
"""Module containing bug report helper(s)."""
12
from . import __version__ as requests_version
15
import charset_normalizer
17
charset_normalizer = None
25
from urllib3.contrib import pyopenssl
36
"""Return a dict with the Python implementation and version.
38
Provide both the name and the version of the Python implementation
39
currently running. For example, on CPython 3.10.3 it will return
40
{'name': 'CPython', 'version': '3.10.3'}.
42
This function works best on CPython and PyPy: in particular, it probably
43
doesn't work for Jython or IronPython. Future investigation should be done
44
to work out the correct shape of the code for those platforms.
46
implementation = platform.python_implementation()
48
if implementation == "CPython":
49
implementation_version = platform.python_version()
50
elif implementation == "PyPy":
51
pypy = sys.pypy_version_info # type: ignore[attr-defined]
52
implementation_version = f"{pypy.major}.{pypy.minor}.{pypy.micro}" # pyright: ignore[reportUnknownMemberType]
53
if sys.pypy_version_info.releaselevel != "final": # type: ignore[attr-defined]
54
implementation_version = "".join(
55
[implementation_version, sys.pypy_version_info.releaselevel] # type: ignore[attr-defined]
57
elif implementation == "Jython":
58
implementation_version = platform.python_version() # Complete Guess
59
elif implementation == "IronPython":
60
implementation_version = platform.python_version() # Complete Guess
62
implementation_version = "Unknown"
58
implementation_version = platform.python_version() # Complete Guess
59
elif implementation == "IronPython":
60
implementation_version = platform.python_version() # Complete Guess
62
implementation_version = "Unknown"
64
return {"name": implementation, "version": implementation_version}
67
def info() -> dict[str, Any]:
68
"""Generate information for a bug report."""
71
"system": platform.system(),
72
"release": platform.release(),
80
implementation_info = _implementation()
81
urllib3_info = {"version": urllib3.__version__}
82
charset_normalizer_info = {"version": None}
83
chardet_info: dict[str, str | None] = {"version": None}
84
if charset_normalizer:
85
charset_normalizer_info = {"version": charset_normalizer.__version__}
87
chardet_info = {"version": chardet.__version__}
89
pyopenssl_info: dict[str, str | None] = {
91
"openssl_version": "",
95
"version": OpenSSL.__version__,
96
"openssl_version": f"{OpenSSL.SSL.OPENSSL_VERSION_NUMBER:x}",
99
"version": getattr(cryptography, "__version__", ""),
102
"version": getattr(idna, "__version__", ""),
99
"version": getattr(cryptography, "__version__", ""),
102
"version": getattr(idna, "__version__", ""),
105
system_ssl = ssl.OPENSSL_VERSION_NUMBER
106
system_ssl_info = {"version": f"{system_ssl:x}" if system_ssl is not None else ""} # type: ignore[reportUnnecessaryComparison]
109
"platform": platform_info,
110
"implementation": implementation_info,
111
"system_ssl": system_ssl_info,
112
"using_pyopenssl": pyopenssl is not None,
113
"using_charset_normalizer": chardet is None,
114
"pyOpenSSL": pyopenssl_info,
115
"urllib3": urllib3_info,
116
"chardet": chardet_info,
117
"charset_normalizer": charset_normalizer_info,
118
"cryptography": cryptography_info,
121
"version": requests_version,
127
"""Pretty-print the bug information as JSON."""
128
print(json.dumps(info(), sort_keys=True, indent=2))
131
if __name__ == "__main__":