DRY scanners more

This commit is contained in:
rocky
2016-05-28 17:07:33 -04:00
parent fca233419f
commit 90741148ad
5 changed files with 18 additions and 32 deletions

View File

@@ -46,7 +46,7 @@ class Scanner3(scan.Scanner):
def __init__(self, version): def __init__(self, version):
super(Scanner3, self).__init__(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'. Disassemble a Python 3 code object, returning a list of 'Token'.
Various tranformations are made to assist the deparsing grammar. Various tranformations are made to assist the deparsing grammar.
@@ -179,7 +179,7 @@ class Scanner3(scan.Scanner):
pass pass
return tokens, {} 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. Like disassemble3 but doesn't try to adjust any opcodes.
""" """

View File

@@ -18,12 +18,8 @@ class Scanner32(Scanner3):
def __init__(self): def __init__(self):
super(Scanner3, self).__init__(3.2) super(Scanner3, self).__init__(3.2)
return
def disassemble(self, co, classname=None, code_objects={}): pass
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)
if __name__ == "__main__": if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION from uncompyle6 import PYTHON_VERSION

View File

@@ -18,12 +18,8 @@ class Scanner33(Scanner3):
def __init__(self): def __init__(self):
super(Scanner3, self).__init__(3.3) super(Scanner3, self).__init__(3.3)
return
def disassemble(self, co, classname=None, code_objects={}): pass
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)
if __name__ == "__main__": if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION from uncompyle6 import PYTHON_VERSION

View File

@@ -8,24 +8,22 @@ scanner routine for Python 3.
from __future__ import print_function from __future__ import print_function
import xdis
# bytecode verification, verify(), uses JUMP_OPs from here # 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 from uncompyle6.scanners.scanner3 import Scanner3
class Scanner34(Scanner3): class Scanner34(Scanner3):
def __init__(self): def __init__(self):
super(Scanner3, self).__init__(3.4) super(Scanner3, self).__init__(3.4)
return
def disassemble(self, co, classname=None, code_objects={}): pass
return self.disassemble3(co, classname, code_objects)
def disassemble_native(self, co, classname=None, code_objects={}):
return self.disassemble3_native(co, classname, code_objects)
if __name__ == "__main__": if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION from uncompyle6 import PYTHON_VERSION
if PYTHON_VERSION >= 3.2: if PYTHON_VERSION == 3.4:
import inspect import inspect
co = inspect.currentframe().f_code co = inspect.currentframe().f_code
tokens, customize = Scanner34().disassemble(co) tokens, customize = Scanner34().disassemble(co)
@@ -33,5 +31,5 @@ if __name__ == "__main__":
print(t) print(t)
pass pass
else: 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) PYTHON_VERSION)

View File

@@ -8,23 +8,19 @@ scanner routine for Python 3.
from __future__ import print_function from __future__ import print_function
import xdis
from uncompyle6.scanners.scanner3 import Scanner3 from uncompyle6.scanners.scanner3 import Scanner3
# bytecode verification, verify(), uses JUMP_OPs from here # bytecode verification, verify(), uses JUMP_OPs from here
from xdis.opcodes.opcode_35 import JUMP_OPs JUMP_OPs = xdis.opcodes.opcode_35.JUMP_OPs
import xdis
class Scanner35(Scanner3): class Scanner35(Scanner3):
def __init__(self): def __init__(self):
super(Scanner35, self).__init__(3.5) super(Scanner35, self).__init__(3.5)
self.opc = xdis.opcodes.opcode_35 return
pass
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)
if __name__ == "__main__": if __name__ == "__main__":
from uncompyle6 import PYTHON_VERSION from uncompyle6 import PYTHON_VERSION