scanner24.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (c) 2016-2017, 2021-2022 by Rocky Bernstein
  2. """
  3. Python 2.4 bytecode massaging.
  4. This massages tokenized 2.7 bytecode to make it more amenable for
  5. grammar parsing.
  6. """
  7. import uncompyle6.scanners.scanner25 as scan
  8. # bytecode verification, verify(), uses JUMP_OPs from here
  9. from xdis.opcodes import opcode_24
  10. JUMP_OPS = opcode_24.JUMP_OPS
  11. # We base this off of 2.5 instead of the other way around
  12. # because we cleaned things up this way.
  13. # The history is that 2.7 support is the cleanest,
  14. # then from that we got 2.6 and so on.
  15. class Scanner24(scan.Scanner25):
  16. def __init__(self, show_asm=False):
  17. scan.Scanner25.__init__(self, show_asm)
  18. # These are the only differences in initialization between
  19. # 2.4, 2.5 and 2.6
  20. self.opc = opcode_24
  21. self.opname = opcode_24.opname
  22. self.version = (2, 4)
  23. self.genexpr_name = "<generator expression>"
  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, 4):
  28. import inspect
  29. co = inspect.currentframe().f_code # type: ignore
  30. tokens, customize = Scanner24().ingest(co)
  31. for t in tokens:
  32. print(t.format())
  33. pass
  34. else:
  35. print("Need to be Python 2.4 to demo; I am version %s" % version_tuple_to_str())