|
| 1 | +from __future__ import print_function |
| 2 | + |
| 3 | +import json |
| 4 | +import platform |
| 5 | +import sys |
| 6 | + |
| 7 | +from . import __version__ as pyjwt_version |
| 8 | + |
| 9 | +try: |
| 10 | + import cryptography |
| 11 | +except ImportError: |
| 12 | + cryptography = None |
| 13 | + |
| 14 | +try: |
| 15 | + import ecdsa |
| 16 | +except ImportError: |
| 17 | + ecdsa = None |
| 18 | + |
| 19 | + |
| 20 | +def info(): |
| 21 | + """ |
| 22 | + Generate information for a bug report. |
| 23 | + Based on the requests package help utility module. |
| 24 | + """ |
| 25 | + try: |
| 26 | + platform_info = {"system": platform.system(), "release": platform.release()} |
| 27 | + except IOError: |
| 28 | + platform_info = {"system": "Unknown", "release": "Unknown"} |
| 29 | + |
| 30 | + implementation = platform.python_implementation() |
| 31 | + |
| 32 | + if implementation == "CPython": |
| 33 | + implementation_version = platform.python_version() |
| 34 | + elif implementation == "PyPy": |
| 35 | + implementation_version = "%s.%s.%s" % ( |
| 36 | + sys.pypy_version_info.major, |
| 37 | + sys.pypy_version_info.minor, |
| 38 | + sys.pypy_version_info.micro, |
| 39 | + ) |
| 40 | + if sys.pypy_version_info.releaselevel != "final": |
| 41 | + implementation_version = "".join( |
| 42 | + [implementation_version, sys.pypy_version_info.releaselevel] |
| 43 | + ) |
| 44 | + else: |
| 45 | + implementation_version = "Unknown" |
| 46 | + |
| 47 | + return { |
| 48 | + "platform": platform_info, |
| 49 | + "implementation": {"name": implementation, "version": implementation_version}, |
| 50 | + "cryptography": {"version": getattr(cryptography, "__version__", "")}, |
| 51 | + "pyjwt": {"version": pyjwt_version}, |
| 52 | + } |
| 53 | + |
| 54 | + |
| 55 | +def main(): |
| 56 | + """Pretty-print the bug information as JSON.""" |
| 57 | + print(json.dumps(info(), sort_keys=True, indent=2)) |
| 58 | + |
| 59 | + |
| 60 | +if __name__ == "__main__": |
| 61 | + main() |
0 commit comments