add info about chardet and urllib3
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Kenneth Reitz · committed by Kenneth Reitz · parent f180980 · Browse files · 2 files·+110 added−99 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+110 added−99 removed
- other:+110 added−99 removed
Provenance
- Commit
6d082ea- Tree
235ed6c- Author
Kenneth Reitz <me@kennethreitz.org>- Committer
Kenneth Reitz <me@kennethreitz.org>- Parent
f180980
2 files changed+110 added−99 removed
deleted:requests/_bug.py-99 removed
1-"""Module containing bug report helper(s)."""2-from __future__ import print_function3-4-import json5-import platform6-import sys7-import ssl8-9-from . import __version__ as requests_version10-11-try:12- from .packages.urllib3.contrib import pyopenssl13-except ImportError:14- pyopenssl = None15- OpenSSL = None16- cryptography = None17-else:18- import OpenSSL19- import cryptography20-21-22-def _implementation():23- """Return a dict with the Python implementation and verison.24-25- Provide both the name and the version of the Python implementation26- currently running. For example, on CPython 2.7.5 it will return27- {'name': 'CPython', 'version': '2.7.5'}.28-29- This function works best on CPython and PyPy: in particular, it probably30- doesn't work for Jython or IronPython. Future investigation should be done31- to work out the correct shape of the code for those platforms.32- """33- implementation = platform.python_implementation()34-35- if implementation == 'CPython':36- implementation_version = platform.python_version()37- elif implementation == 'PyPy':38- implementation_version = '%s.%s.%s' % (sys.pypy_version_info.major,39- sys.pypy_version_info.minor,40- sys.pypy_version_info.micro)41- if sys.pypy_version_info.releaselevel != 'final':42- implementation_version = ''.join([43- implementation_version, sys.pypy_version_info.releaselevel44- ])45- elif implementation == 'Jython':46- implementation_version = platform.python_version() # Complete Guess47- elif implementation == 'IronPython':48- implementation_version = platform.python_version() # Complete Guess49- else:50- implementation_version = 'Unknown'51-52- return {'name': implementation, 'version': implementation_version}53-54-55-def information():56- """Generate information for a bug report."""57- try:58- platform_info = {59- 'system': platform.system(),60- 'release': platform.release(),61- }62- except IOError:63- platform_info = {64- 'system': 'Unknown',65- 'release': 'Unknown',66- }67-68- implementation_info = _implementation()69- pyopenssl_info = {70- 'version': None,71- 'openssl_version': '',72- }73- if OpenSSL:74- pyopenssl_info = {75- 'version': OpenSSL.__version__,76- 'openssl_version': '%x' % OpenSSL.SSL.OPENSSL_VERSION_NUMBER,77- }78- cryptography_info = {79- 'version': getattr(cryptography, '__version__', ''),80- }81-82- return {83- 'platform': platform_info,84- 'implementation': implementation_info,85- 'system_ssl': {86- 'version': '%x' % ssl.OPENSSL_VERSION_NUMBER,87- },88- 'using_pyopenssl': pyopenssl is not None,89- 'pyOpenSSL': pyopenssl_info,90- 'cryptography': cryptography_info,91- 'requests': {92- 'version': requests_version,93- },94- }95-96-97-def print_information():98- """Pretty-print the bug information as JSON."""99- print(json.dumps(information(), sort_keys=True, indent=2))added:requests/help.py+110 added
1+"""Module containing bug report helper(s)."""2+from __future__ import print_function3+4+import json5+import platform6+import sys7+import ssl8+9+import urllib310+import chardet11+12+from . import __version__ as requests_version13+14+try:15+ from .packages.urllib3.contrib import pyopenssl16+except ImportError:17+ pyopenssl = None18+ OpenSSL = None19+ cryptography = None20+else:21+ import OpenSSL22+ import cryptography23+24+25+def _implementation():26+ """Return a dict with the Python implementation and verison.27+28+ Provide both the name and the version of the Python implementation29+ currently running. For example, on CPython 2.7.5 it will return30+ {'name': 'CPython', 'version': '2.7.5'}.31+32+ This function works best on CPython and PyPy: in particular, it probably33+ doesn't work for Jython or IronPython. Future investigation should be done34+ to work out the correct shape of the code for those platforms.35+ """36+ implementation = platform.python_implementation()37+38+ if implementation == 'CPython':39+ implementation_version = platform.python_version()40+ elif implementation == 'PyPy':41+ implementation_version = '%s.%s.%s' % (sys.pypy_version_info.major,42+ sys.pypy_version_info.minor,43+ sys.pypy_version_info.micro)44+ if sys.pypy_version_info.releaselevel != 'final':45+ implementation_version = ''.join([46+ implementation_version, sys.pypy_version_info.releaselevel47+ ])48+ elif implementation == 'Jython':49+ implementation_version = platform.python_version() # Complete Guess50+ elif implementation == 'IronPython':51+ implementation_version = platform.python_version() # Complete Guess52+ else:53+ implementation_version = 'Unknown'54+55+ return {'name': implementation, 'version': implementation_version}56+57+58+def information():59+ """Generate information for a bug report."""60+ try:61+ platform_info = {62+ 'system': platform.system(),63+ 'release': platform.release(),64+ }65+ except IOError:66+ platform_info = {67+ 'system': 'Unknown',68+ 'release': 'Unknown',69+ }70+71+ implementation_info = _implementation()72+ urllib3_info = urllib3.__version__73+ chardet_info = chardet.__version__74+75+ pyopenssl_info = {76+ 'version': None,77+ 'openssl_version': '',78+ }79+ if OpenSSL:80+ pyopenssl_info = {81+ 'version': OpenSSL.__version__,82+ 'openssl_version': '%x' % OpenSSL.SSL.OPENSSL_VERSION_NUMBER,83+ }84+ cryptography_info = {85+ 'version': getattr(cryptography, '__version__', ''),86+ }87+88+ return {89+ 'platform': platform_info,90+ 'implementation': implementation_info,91+ 'system_ssl': {92+ 'version': '%x' % ssl.OPENSSL_VERSION_NUMBER,93+ },94+ 'using_pyopenssl': pyopenssl is not None,95+ 'pyOpenSSL': pyopenssl_info,96+ 'urllib3': urllib3_info,97+ 'chardet': chardet_info,98+ 'cryptography': cryptography_info,99+ 'requests': {100+ 'version': requests_version,101+ },102+ }103+104+def main():105+ """Pretty-print the bug information as JSON."""106+ print(json.dumps(information(), sort_keys=True, indent=2))107+108+if __name__ == '__main__':109+ main()110+