Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.8KB

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