You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
DRY scanners more
This commit is contained in:
@@ -46,7 +46,7 @@ class Scanner3(scan.Scanner):
|
||||
def __init__(self, version):
|
||||
super(Scanner3, self).__init__(version)
|
||||
|
||||
def disassemble3(self, co, classname=None, code_objects={}):
|
||||
def disassemble(self, co, classname=None, code_objects={}):
|
||||
"""
|
||||
Disassemble a Python 3 code object, returning a list of 'Token'.
|
||||
Various tranformations are made to assist the deparsing grammar.
|
||||
@@ -179,7 +179,7 @@ class Scanner3(scan.Scanner):
|
||||
pass
|
||||
return tokens, {}
|
||||
|
||||
def disassemble3_native(self, co, classname=None, code_objects={}):
|
||||
def disassemble_native(self, co, classname=None, code_objects={}):
|
||||
"""
|
||||
Like disassemble3 but doesn't try to adjust any opcodes.
|
||||
"""
|
||||
|
@@ -18,12 +18,8 @@ class Scanner32(Scanner3):
|
||||
|
||||
def __init__(self):
|
||||
super(Scanner3, self).__init__(3.2)
|
||||
|
||||
def disassemble(self, co, classname=None, code_objects={}):
|
||||
return self.disassemble_generic(co, classname, code_objects=code_objects)
|
||||
|
||||
def disassemble_native(self, co, classname=None, code_objects={}):
|
||||
return self.disassemble3_native(co, classname, code_objects)
|
||||
return
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
from uncompyle6 import PYTHON_VERSION
|
||||
|
@@ -18,12 +18,8 @@ class Scanner33(Scanner3):
|
||||
|
||||
def __init__(self):
|
||||
super(Scanner3, self).__init__(3.3)
|
||||
|
||||
def disassemble(self, co, classname=None, code_objects={}):
|
||||
return self.disassemble_generic(co, classname, code_objects=code_objects)
|
||||
|
||||
def disassemble_native(self, co, classname=None, code_objects={}):
|
||||
return self.disassemble3_native(co, classname, code_objects)
|
||||
return
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
from uncompyle6 import PYTHON_VERSION
|
||||
|
@@ -8,24 +8,22 @@ scanner routine for Python 3.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import xdis
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
from xdis.opcodes.opcode_34 import JUMP_OPs
|
||||
JUMP_OPs = xdis.opcodes.opcode_34.JUMP_OPs
|
||||
|
||||
from uncompyle6.scanners.scanner3 import Scanner3
|
||||
class Scanner34(Scanner3):
|
||||
|
||||
def __init__(self):
|
||||
super(Scanner3, self).__init__(3.4)
|
||||
|
||||
def disassemble(self, co, classname=None, code_objects={}):
|
||||
return self.disassemble3(co, classname, code_objects)
|
||||
|
||||
def disassemble_native(self, co, classname=None, code_objects={}):
|
||||
return self.disassemble3_native(co, classname, code_objects)
|
||||
return
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
from uncompyle6 import PYTHON_VERSION
|
||||
if PYTHON_VERSION >= 3.2:
|
||||
if PYTHON_VERSION == 3.4:
|
||||
import inspect
|
||||
co = inspect.currentframe().f_code
|
||||
tokens, customize = Scanner34().disassemble(co)
|
||||
@@ -33,5 +31,5 @@ if __name__ == "__main__":
|
||||
print(t)
|
||||
pass
|
||||
else:
|
||||
print("Need to be Python 3.2 or greater to demo; I am %s." %
|
||||
print("Need to be Python 3.4 to demo; I am %s." %
|
||||
PYTHON_VERSION)
|
||||
|
@@ -8,23 +8,19 @@ scanner routine for Python 3.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import xdis
|
||||
|
||||
from uncompyle6.scanners.scanner3 import Scanner3
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
from xdis.opcodes.opcode_35 import JUMP_OPs
|
||||
import xdis
|
||||
JUMP_OPs = xdis.opcodes.opcode_35.JUMP_OPs
|
||||
|
||||
class Scanner35(Scanner3):
|
||||
|
||||
def __init__(self):
|
||||
super(Scanner35, self).__init__(3.5)
|
||||
self.opc = xdis.opcodes.opcode_35
|
||||
|
||||
def disassemble(self, co, classname=None, code_objects={}):
|
||||
return self.disassemble3(co, classname, code_objects)
|
||||
|
||||
def disassemble_native(self, co, classname=None, code_objects={}):
|
||||
return self.disassemble3_native(co, classname, code_objects)
|
||||
return
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
from uncompyle6 import PYTHON_VERSION
|
||||
|
Reference in New Issue
Block a user