scanner25.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (c) 2015-2018, 2021-2022 by Rocky Bernstein
  2. """
  3. Python 2.5 bytecode massaging.
  4. This overlaps Python's 2.5's dis module, but it can be run from
  5. Python 3 and other versions of Python. Also, we save token
  6. information for later use in deparsing.
  7. """
  8. import uncompyle6.scanners.scanner26 as scan
  9. # bytecode verification, verify(), uses JUMP_OPs from here
  10. from xdis.opcodes import opcode_25
  11. JUMP_OPS = opcode_25.JUMP_OPS
  12. # We base this off of 2.6 instead of the other way around
  13. # because we cleaned things up this way.
  14. # The history is that 2.7 support is the cleanest,
  15. # then from that we got 2.6 and so on.
  16. class Scanner25(scan.Scanner26):
  17. def __init__(self, show_asm=False):
  18. # There are no differences in initialization between
  19. # 2.5 and 2.6
  20. self.opc = opcode_25
  21. self.opname = opcode_25.opname
  22. scan.Scanner26.__init__(self, show_asm)
  23. self.version = (2, 5)
  24. return
  25. if __name__ == "__main__":
  26. from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
  27. if PYTHON_VERSION_TRIPLE[:2] == (2, 5):
  28. import inspect
  29. co = inspect.currentframe().f_code # type: ignore
  30. tokens, customize = Scanner25().ingest(co)
  31. for t in tokens:
  32. print(t.format())
  33. pass
  34. else:
  35. print("Need to be Python 2.5 to demo; I am version %s" % version_tuple_to_str())