Limited support for Python 2.3

This commit is contained in:
rocky
2016-06-03 10:09:39 -04:00
parent eefbc40eef
commit ebcb1d08f4
20 changed files with 1301 additions and 76 deletions

View File

@@ -32,12 +32,12 @@ from xdis.bytecode import findlinestarts
import uncompyle6.scanner as scan
class Scanner2(scan.Scanner):
def __init__(self, version, show_asm=False):
def __init__(self, version, show_asm=None):
scan.Scanner.__init__(self, version, show_asm)
self.pop_jump_if = frozenset([self.opc.PJIF, self.opc.PJIT])
self.jump_forward = frozenset([self.opc.JA, self.opc.JF])
def disassemble(self, co, classname=None, code_objects={}):
def disassemble(self, co, classname=None, code_objects={}, show_asm=None):
"""
Disassemble a Python 2 code object, returning a list of 'Token'.
Various tranformations are made to assist the deparsing grammar.
@@ -49,11 +49,12 @@ class Scanner2(scan.Scanner):
dis.disassemble().
"""
# DEBUG
# from xdis.bytecode import Bytecode
# bytecode = Bytecode(co, self.opc)
# for instr in bytecode.get_instructions(co):
# print(instr._disassemble())
show_asm = self.show_asm if not show_asm else show_asm
if self.show_asm in ('both', 'before'):
from xdis.bytecode import Bytecode
bytecode = Bytecode(co, self.opc)
for instr in bytecode.get_instructions(co):
print(instr._disassemble())
# Container for tokens
tokens = []
@@ -207,7 +208,7 @@ class Scanner2(scan.Scanner):
pass
pass
if self.show_asm:
if self.show_asm in ('both', 'after'):
for t in tokens:
print(t)
print()