annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/requests/help.py @ 68:5028fdace37b

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 16:23:26 -0400
parents
children
rev   line source
jpayne@68 1 """Module containing bug report helper(s)."""
jpayne@68 2
jpayne@68 3 import json
jpayne@68 4 import platform
jpayne@68 5 import ssl
jpayne@68 6 import sys
jpayne@68 7
jpayne@68 8 import idna
jpayne@68 9 import urllib3
jpayne@68 10
jpayne@68 11 from . import __version__ as requests_version
jpayne@68 12
jpayne@68 13 try:
jpayne@68 14 import charset_normalizer
jpayne@68 15 except ImportError:
jpayne@68 16 charset_normalizer = None
jpayne@68 17
jpayne@68 18 try:
jpayne@68 19 import chardet
jpayne@68 20 except ImportError:
jpayne@68 21 chardet = None
jpayne@68 22
jpayne@68 23 try:
jpayne@68 24 from urllib3.contrib import pyopenssl
jpayne@68 25 except ImportError:
jpayne@68 26 pyopenssl = None
jpayne@68 27 OpenSSL = None
jpayne@68 28 cryptography = None
jpayne@68 29 else:
jpayne@68 30 import cryptography
jpayne@68 31 import OpenSSL
jpayne@68 32
jpayne@68 33
jpayne@68 34 def _implementation():
jpayne@68 35 """Return a dict with the Python implementation and version.
jpayne@68 36
jpayne@68 37 Provide both the name and the version of the Python implementation
jpayne@68 38 currently running. For example, on CPython 3.10.3 it will return
jpayne@68 39 {'name': 'CPython', 'version': '3.10.3'}.
jpayne@68 40
jpayne@68 41 This function works best on CPython and PyPy: in particular, it probably
jpayne@68 42 doesn't work for Jython or IronPython. Future investigation should be done
jpayne@68 43 to work out the correct shape of the code for those platforms.
jpayne@68 44 """
jpayne@68 45 implementation = platform.python_implementation()
jpayne@68 46
jpayne@68 47 if implementation == "CPython":
jpayne@68 48 implementation_version = platform.python_version()
jpayne@68 49 elif implementation == "PyPy":
jpayne@68 50 implementation_version = "{}.{}.{}".format(
jpayne@68 51 sys.pypy_version_info.major,
jpayne@68 52 sys.pypy_version_info.minor,
jpayne@68 53 sys.pypy_version_info.micro,
jpayne@68 54 )
jpayne@68 55 if sys.pypy_version_info.releaselevel != "final":
jpayne@68 56 implementation_version = "".join(
jpayne@68 57 [implementation_version, sys.pypy_version_info.releaselevel]
jpayne@68 58 )
jpayne@68 59 elif implementation == "Jython":
jpayne@68 60 implementation_version = platform.python_version() # Complete Guess
jpayne@68 61 elif implementation == "IronPython":
jpayne@68 62 implementation_version = platform.python_version() # Complete Guess
jpayne@68 63 else:
jpayne@68 64 implementation_version = "Unknown"
jpayne@68 65
jpayne@68 66 return {"name": implementation, "version": implementation_version}
jpayne@68 67
jpayne@68 68
jpayne@68 69 def info():
jpayne@68 70 """Generate information for a bug report."""
jpayne@68 71 try:
jpayne@68 72 platform_info = {
jpayne@68 73 "system": platform.system(),
jpayne@68 74 "release": platform.release(),
jpayne@68 75 }
jpayne@68 76 except OSError:
jpayne@68 77 platform_info = {
jpayne@68 78 "system": "Unknown",
jpayne@68 79 "release": "Unknown",
jpayne@68 80 }
jpayne@68 81
jpayne@68 82 implementation_info = _implementation()
jpayne@68 83 urllib3_info = {"version": urllib3.__version__}
jpayne@68 84 charset_normalizer_info = {"version": None}
jpayne@68 85 chardet_info = {"version": None}
jpayne@68 86 if charset_normalizer:
jpayne@68 87 charset_normalizer_info = {"version": charset_normalizer.__version__}
jpayne@68 88 if chardet:
jpayne@68 89 chardet_info = {"version": chardet.__version__}
jpayne@68 90
jpayne@68 91 pyopenssl_info = {
jpayne@68 92 "version": None,
jpayne@68 93 "openssl_version": "",
jpayne@68 94 }
jpayne@68 95 if OpenSSL:
jpayne@68 96 pyopenssl_info = {
jpayne@68 97 "version": OpenSSL.__version__,
jpayne@68 98 "openssl_version": f"{OpenSSL.SSL.OPENSSL_VERSION_NUMBER:x}",
jpayne@68 99 }
jpayne@68 100 cryptography_info = {
jpayne@68 101 "version": getattr(cryptography, "__version__", ""),
jpayne@68 102 }
jpayne@68 103 idna_info = {
jpayne@68 104 "version": getattr(idna, "__version__", ""),
jpayne@68 105 }
jpayne@68 106
jpayne@68 107 system_ssl = ssl.OPENSSL_VERSION_NUMBER
jpayne@68 108 system_ssl_info = {"version": f"{system_ssl:x}" if system_ssl is not None else ""}
jpayne@68 109
jpayne@68 110 return {
jpayne@68 111 "platform": platform_info,
jpayne@68 112 "implementation": implementation_info,
jpayne@68 113 "system_ssl": system_ssl_info,
jpayne@68 114 "using_pyopenssl": pyopenssl is not None,
jpayne@68 115 "using_charset_normalizer": chardet is None,
jpayne@68 116 "pyOpenSSL": pyopenssl_info,
jpayne@68 117 "urllib3": urllib3_info,
jpayne@68 118 "chardet": chardet_info,
jpayne@68 119 "charset_normalizer": charset_normalizer_info,
jpayne@68 120 "cryptography": cryptography_info,
jpayne@68 121 "idna": idna_info,
jpayne@68 122 "requests": {
jpayne@68 123 "version": requests_version,
jpayne@68 124 },
jpayne@68 125 }
jpayne@68 126
jpayne@68 127
jpayne@68 128 def main():
jpayne@68 129 """Pretty-print the bug information as JSON."""
jpayne@68 130 print(json.dumps(info(), sort_keys=True, indent=2))
jpayne@68 131
jpayne@68 132
jpayne@68 133 if __name__ == "__main__":
jpayne@68 134 main()