Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

help.py 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. """Module containing bug report helper(s)."""
  2. from __future__ import print_function
  3. import json
  4. import platform
  5. import sys
  6. import ssl
  7. from pip._vendor import idna
  8. from pip._vendor import urllib3
  9. from pip._vendor import chardet
  10. from . import __version__ as requests_version
  11. try:
  12. from pip._vendor.urllib3.contrib import pyopenssl
  13. except ImportError:
  14. pyopenssl = None
  15. OpenSSL = None
  16. cryptography = None
  17. else:
  18. import OpenSSL
  19. import cryptography
  20. def _implementation():
  21. """Return a dict with the Python implementation and version.
  22. Provide both the name and the version of the Python implementation
  23. currently running. For example, on CPython 2.7.5 it will return
  24. {'name': 'CPython', 'version': '2.7.5'}.
  25. This function works best on CPython and PyPy: in particular, it probably
  26. doesn't work for Jython or IronPython. Future investigation should be done
  27. to work out the correct shape of the code for those platforms.
  28. """
  29. implementation = platform.python_implementation()
  30. if implementation == 'CPython':
  31. implementation_version = platform.python_version()
  32. elif implementation == 'PyPy':
  33. implementation_version = '%s.%s.%s' % (sys.pypy_version_info.major,
  34. sys.pypy_version_info.minor,
  35. sys.pypy_version_info.micro)
  36. if sys.pypy_version_info.releaselevel != 'final':
  37. implementation_version = ''.join([
  38. implementation_version, sys.pypy_version_info.releaselevel
  39. ])
  40. elif implementation == 'Jython':
  41. implementation_version = platform.python_version() # Complete Guess
  42. elif implementation == 'IronPython':
  43. implementation_version = platform.python_version() # Complete Guess
  44. else:
  45. implementation_version = 'Unknown'
  46. return {'name': implementation, 'version': implementation_version}
  47. def info():
  48. """Generate information for a bug report."""
  49. try:
  50. platform_info = {
  51. 'system': platform.system(),
  52. 'release': platform.release(),
  53. }
  54. except IOError:
  55. platform_info = {
  56. 'system': 'Unknown',
  57. 'release': 'Unknown',
  58. }
  59. implementation_info = _implementation()
  60. urllib3_info = {'version': urllib3.__version__}
  61. chardet_info = {'version': chardet.__version__}
  62. pyopenssl_info = {
  63. 'version': None,
  64. 'openssl_version': '',
  65. }
  66. if OpenSSL:
  67. pyopenssl_info = {
  68. 'version': OpenSSL.__version__,
  69. 'openssl_version': '%x' % OpenSSL.SSL.OPENSSL_VERSION_NUMBER,
  70. }
  71. cryptography_info = {
  72. 'version': getattr(cryptography, '__version__', ''),
  73. }
  74. idna_info = {
  75. 'version': getattr(idna, '__version__', ''),
  76. }
  77. # OPENSSL_VERSION_NUMBER doesn't exist in the Python 2.6 ssl module.
  78. system_ssl = getattr(ssl, 'OPENSSL_VERSION_NUMBER', None)
  79. system_ssl_info = {
  80. 'version': '%x' % system_ssl if system_ssl is not None else ''
  81. }
  82. return {
  83. 'platform': platform_info,
  84. 'implementation': implementation_info,
  85. 'system_ssl': system_ssl_info,
  86. 'using_pyopenssl': pyopenssl is not None,
  87. 'pyOpenSSL': pyopenssl_info,
  88. 'urllib3': urllib3_info,
  89. 'chardet': chardet_info,
  90. 'cryptography': cryptography_info,
  91. 'idna': idna_info,
  92. 'requests': {
  93. 'version': requests_version,
  94. },
  95. }
  96. def main():
  97. """Pretty-print the bug information as JSON."""
  98. print(json.dumps(info(), sort_keys=True, indent=2))
  99. if __name__ == '__main__':
  100. main()