annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/lib/python3.8/site-packages/requests/help.py @ 69:33d812a61356

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