Scanner call fixes. NAME_MODULE removal for <=2.4

This commit is contained in:
rocky
2016-12-25 09:20:57 -05:00
parent e3f4beeb74
commit 2f51067a9d
4 changed files with 31 additions and 17 deletions

View File

@@ -2,9 +2,8 @@
""" """
Python 2.3 bytecode scanner/deparser Python 2.3 bytecode scanner/deparser
This overlaps Python's 2.3's dis module, but it can be run from This massages tokenized 2.3 bytecode to make it more amenable for
Python 3 and other versions of Python. Also, we save token grammar parsing.
information for later use in deparsing.
""" """
import uncompyle6.scanners.scanner24 as scan import uncompyle6.scanners.scanner24 as scan
@@ -13,12 +12,12 @@ import uncompyle6.scanners.scanner24 as scan
from xdis.opcodes import opcode_23 from xdis.opcodes import opcode_23
JUMP_OPs = opcode_23.JUMP_OPs JUMP_OPs = opcode_23.JUMP_OPs
# We base this off of 2.5 instead of the other way around # We base this off of 2.4 instead of the other way around
# because we cleaned things up this way. # because we cleaned things up this way.
# The history is that 2.7 support is the cleanest, # The history is that 2.7 support is the cleanest,
# then from that we got 2.6 and so on. # then from that we got 2.6 and so on.
class Scanner23(scan.Scanner24): class Scanner23(scan.Scanner24):
def __init__(self, show_asm): def __init__(self, show_asm=False):
scan.Scanner24.__init__(self, show_asm) scan.Scanner24.__init__(self, show_asm)
self.opc = opcode_23 self.opc = opcode_23
self.opname = opcode_23.opname self.opname = opcode_23.opname

View File

@@ -2,9 +2,8 @@
""" """
Python 2.4 bytecode scanner/deparser Python 2.4 bytecode scanner/deparser
This overlaps Python's 2.4's dis module, but it can be run from This massages tokenized 2.7 bytecode to make it more amenable for
Python 3 and other versions of Python. Also, we save token grammar parsing.
information for later use in deparsing.
""" """
import uncompyle6.scanners.scanner25 as scan import uncompyle6.scanners.scanner25 as scan
@@ -18,7 +17,7 @@ JUMP_OPs = opcode_24.JUMP_OPs
# The history is that 2.7 support is the cleanest, # The history is that 2.7 support is the cleanest,
# then from that we got 2.6 and so on. # then from that we got 2.6 and so on.
class Scanner24(scan.Scanner25): class Scanner24(scan.Scanner25):
def __init__(self, show_asm): def __init__(self, show_asm=False):
scan.Scanner25.__init__(self, show_asm) scan.Scanner25.__init__(self, show_asm)
# These are the only differences in initialization between # These are the only differences in initialization between
# 2.4, 2.5 and 2.6 # 2.4, 2.5 and 2.6

View File

@@ -131,12 +131,16 @@ BUILD_TUPLE_0 = AST('expr',
NAME_MODULE = AST('stmt', NAME_MODULE = AST('stmt',
[ AST('assign', [ AST('assign',
[ AST('expr', [Token('LOAD_NAME', pattr='__name__')]), [ AST('expr',
AST('designator', [ Token('STORE_NAME', pattr='__module__')]) [Token('LOAD_NAME', pattr='__name__', offset=0, has_arg=True)]),
AST('designator',
[ Token('STORE_NAME', pattr='__module__', offset=3, has_arg=True)])
])]) ])])
# TAB = '\t' # as God intended # God intended \t, but Python has decided to use 4 spaces.
TAB = ' ' *4 # is less spacy than "\t" # If you want real tabs, use Go.
# TAB = '\t'
TAB = ' ' * 4
INDENT_PER_LEVEL = ' ' # additional intent per pretty-print level INDENT_PER_LEVEL = ' ' # additional intent per pretty-print level
TABLE_R = { TABLE_R = {
@@ -544,6 +548,18 @@ class SourceWalker(GenericASTTraversal, object):
TABLE_DIRECT.update({ TABLE_DIRECT.update({
'importlist2': ( '%C', (0, maxint, ', ') ), 'importlist2': ( '%C', (0, maxint, ', ') ),
}) })
if version <= 2.4:
global NAME_MODULE
NAME_MODULE = AST('stmt',
[ AST('assign',
[ AST('expr',
[Token('LOAD_GLOBAL', pattr='__name__',
offset=0, has_arg=True)]),
AST('designator',
[ Token('STORE_NAME', pattr='__module__',
offset=3, has_arg=True)])
])])
pass
if version <= 2.3: if version <= 2.3:
TABLE_DIRECT.update({ TABLE_DIRECT.update({
'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 4 ) 'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 4 )

View File

@@ -184,16 +184,16 @@ def cmp_code_objects(version, is_pypy, code_obj1, code_obj2,
elif member == 'co_code' and not ignore_code: elif member == 'co_code' and not ignore_code:
if version == 2.3: if version == 2.3:
import uncompyle6.scanners.scanner23 as scan import uncompyle6.scanners.scanner23 as scan
scanner = scan.Scanner26() scanner = scan.Scanner23(show_asm=False)
elif version == 2.4: elif version == 2.4:
import uncompyle6.scanners.scanner24 as scan import uncompyle6.scanners.scanner24 as scan
scanner = scan.Scanner25() scanner = scan.Scanner24(show_asm=False)
elif version == 2.5: elif version == 2.5:
import uncompyle6.scanners.scanner25 as scan import uncompyle6.scanners.scanner25 as scan
scanner = scan.Scanner25() scanner = scan.Scanner25(show_asm=False)
elif version == 2.6: elif version == 2.6:
import uncompyle6.scanners.scanner26 as scan import uncompyle6.scanners.scanner26 as scan
scanner = scan.Scanner26() scanner = scan.Scanner26(show_asm=False)
elif version == 2.7: elif version == 2.7:
if is_pypy: if is_pypy:
import uncompyle6.scanners.pypy27 as scan import uncompyle6.scanners.pypy27 as scan