Skip to content
Myr

Add debugging submodule for bug reporters

Before adoption: this commit came in with the history the project adopted, so no landing records it.

The suggested usage in a bug report would be python -c 'from requests import _bug; _bug.print_information()' This should generate most of the information we tend to ask for repeatedly from bug reporters.

authored by Ian Cordasco · committed by Ian Cordasco · parent 993cbf5 · Browse files · 1 file+99 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+99 added−0 removed

  • other:+99 added−0 removed

1 file+99 added−0 removed

added:requests/_bug.py+99 added
1"""Module containing bug report helper(s)."""2from __future__ import print_function34import json5import platform6import sys7import ssl89from . import __version__ as requests_version1011try:12 from .packages.urllib3.contrib import pyopenssl13except ImportError:14 pyopenssl = None15 OpenSSL = None16 cryptography = None17else:18 import OpenSSL19 import cryptography202122def _implementation():23 """Return a dict with the Python implementation and verison.2425 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'}.2829 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()3435 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'5152 return {'name': implementation, 'version': implementation_version}535455def 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 }6768 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 }8182 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 }959697def print_information():98 """Pretty-print the bug information as JSON."""99 print(json.dumps(information(), sort_keys=True, indent=2))