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