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

@@ -21,6 +21,9 @@ import sys
from uncompyle6 import PYTHON3
from uncompyle6.scanners.tok import Token
# The byte code versions we support
PYTHON_VERSIONS = (2.3, 2.4, 2.5, 2.6, 2.7, 3.2, 3.3, 3.4, 3.5)
# FIXME: DRY
if PYTHON3:
intern = sys.intern
@@ -45,35 +48,14 @@ class Code(object):
class Scanner(object):
def __init__(self, version, show_asm=False):
def __init__(self, version, show_asm=None):
self.version = version
self.show_asm = show_asm
# FIXME: DRY
if version == 2.7:
from xdis.opcodes import opcode_27
self.opc = opcode_27
elif version == 2.3:
from xdis.opcodes import opcode_23
self.opc = opcode_23
elif version == 2.6:
from xdis.opcodes import opcode_26
self.opc = opcode_26
elif version == 2.5:
from xdis.opcodes import opcode_25
self.opc = opcode_25
elif version == 3.2:
from xdis.opcodes import opcode_32
self.opc = opcode_32
elif version == 3.3:
from xdis.opcodes import opcode_33
self.opc = opcode_33
elif version == 3.4:
from xdis.opcodes import opcode_34
self.opc = opcode_34
elif version == 3.5:
from xdis.opcodes import opcode_35
self.opc = opcode_35
if version in PYTHON_VERSIONS:
v_str = "opcode_%s" % (int(version * 10))
exec("from xdis.opcodes import %s" % v_str)
exec("self.opc = %s" % v_str)
else:
raise TypeError("%s is not a Python version I know about" % version)
@@ -288,34 +270,10 @@ class Scanner(object):
def get_scanner(version, show_asm=False):
# Pick up appropriate scanner
# from trepan.api import debug;
# debug(start_opts={'startup-profile': True})
# FIXME: see if we can do better
if version == 2.7:
import uncompyle6.scanners.scanner27 as scan
scanner = scan.Scanner27(show_asm=show_asm)
elif version == 2.3:
import uncompyle6.scanners.scanner23 as scan
scanner = scan.Scanner23(show_asm)
elif version == 2.6:
import uncompyle6.scanners.scanner26 as scan
scanner = scan.Scanner26(show_asm)
elif version == 2.5:
import uncompyle6.scanners.scanner25 as scan
scanner = scan.Scanner25(show_asm)
elif version == 3.2:
import uncompyle6.scanners.scanner32 as scan
scanner = scan.Scanner32(show_asm)
elif version == 3.3:
import uncompyle6.scanners.scanner33 as scan
scanner = scan.Scanner33(show_asm)
elif version == 3.4:
import uncompyle6.scanners.scanner34 as scan
scanner = scan.Scanner34(show_asm)
elif version == 3.5:
import uncompyle6.scanners.scanner35 as scan
scanner = scan.Scanner35(show_asm)
if version in PYTHON_VERSIONS:
v_str = "%s" % (int(version * 10))
exec("import uncompyle6.scanners.scanner%s as scan" % v_str)
exec("scanner = scan.Scanner%s(show_asm=show_asm)" % v_str)
else:
raise RuntimeError("Unsupported Python version %s" % version)
return scanner