scanner33.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (c) 2015-2019, 2021-2022, 2024 by Rocky Bernstein
  2. #
  3. # This program is free software: you can redistribute it and/or modify
  4. # it under the terms of the GNU General Public License as published by
  5. # the Free Software Foundation, either version 3 of the License, or
  6. # (at your option) any later version.
  7. #
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU General Public License
  14. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. """
  16. Python 3.3 bytecode scanner/deparser
  17. This sets up opcodes Python's 3.3 and calls a generalized
  18. scanner routine for Python 3.
  19. """
  20. # bytecode verification, verify(), uses JUMP_OPs from here
  21. from xdis.opcodes import opcode_33 as opc
  22. from uncompyle6.scanners.scanner3 import Scanner3
  23. JUMP_OPS = opc.JUMP_OPS
  24. class Scanner33(Scanner3):
  25. def __init__(self, show_asm=False, is_pypy=False):
  26. Scanner3.__init__(self, (3, 3), show_asm)
  27. return
  28. pass
  29. if __name__ == "__main__":
  30. from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
  31. if PYTHON_VERSION_TRIPLE[:2] == (3, 3):
  32. import inspect
  33. co = inspect.currentframe().f_code # type: ignore
  34. tokens, customize = Scanner33().ingest(co)
  35. for t in tokens:
  36. print(t.format())
  37. pass
  38. else:
  39. print("Need to be Python 3.3 to demo; I am version %s" % version_tuple_to_str())