Path: blob/master/venv/Lib/site-packages/requests/help.py
811 views
"""Module containing bug report helper(s)."""1from __future__ import print_function23import json4import platform5import sys6import ssl78import idna9import urllib310import chardet1112from . import __version__ as requests_version1314try:15from urllib3.contrib import pyopenssl16except ImportError:17pyopenssl = None18OpenSSL = None19cryptography = None20else:21import OpenSSL22import cryptography232425def _implementation():26"""Return a dict with the Python implementation and version.2728Provide both the name and the version of the Python implementation29currently running. For example, on CPython 2.7.5 it will return30{'name': 'CPython', 'version': '2.7.5'}.3132This function works best on CPython and PyPy: in particular, it probably33doesn't work for Jython or IronPython. Future investigation should be done34to work out the correct shape of the code for those platforms.35"""36implementation = platform.python_implementation()3738if implementation == 'CPython':39implementation_version = platform.python_version()40elif implementation == 'PyPy':41implementation_version = '%s.%s.%s' % (sys.pypy_version_info.major,42sys.pypy_version_info.minor,43sys.pypy_version_info.micro)44if sys.pypy_version_info.releaselevel != 'final':45implementation_version = ''.join([46implementation_version, sys.pypy_version_info.releaselevel47])48elif implementation == 'Jython':49implementation_version = platform.python_version() # Complete Guess50elif implementation == 'IronPython':51implementation_version = platform.python_version() # Complete Guess52else:53implementation_version = 'Unknown'5455return {'name': implementation, 'version': implementation_version}565758def info():59"""Generate information for a bug report."""60try:61platform_info = {62'system': platform.system(),63'release': platform.release(),64}65except IOError:66platform_info = {67'system': 'Unknown',68'release': 'Unknown',69}7071implementation_info = _implementation()72urllib3_info = {'version': urllib3.__version__}73chardet_info = {'version': chardet.__version__}7475pyopenssl_info = {76'version': None,77'openssl_version': '',78}79if OpenSSL:80pyopenssl_info = {81'version': OpenSSL.__version__,82'openssl_version': '%x' % OpenSSL.SSL.OPENSSL_VERSION_NUMBER,83}84cryptography_info = {85'version': getattr(cryptography, '__version__', ''),86}87idna_info = {88'version': getattr(idna, '__version__', ''),89}9091system_ssl = ssl.OPENSSL_VERSION_NUMBER92system_ssl_info = {93'version': '%x' % system_ssl if system_ssl is not None else ''94}9596return {97'platform': platform_info,98'implementation': implementation_info,99'system_ssl': system_ssl_info,100'using_pyopenssl': pyopenssl is not None,101'pyOpenSSL': pyopenssl_info,102'urllib3': urllib3_info,103'chardet': chardet_info,104'cryptography': cryptography_info,105'idna': idna_info,106'requests': {107'version': requests_version,108},109}110111112def main():113"""Pretty-print the bug information as JSON."""114print(json.dumps(info(), sort_keys=True, indent=2))115116117if __name__ == '__main__':118main()119120121