Removing NAME_MODULE, lint and bug fixes

scanner*.py: show_asm param is optional
verify.py: call correct scanners
main.py, verify.py: Use older Python print statements
This commit is contained in:
rocky
2016-12-25 09:02:15 -05:00
parent 012ff91cfb
commit c8a4dcf72b
8 changed files with 38 additions and 24 deletions

View File

@@ -183,10 +183,10 @@ def main(in_base, out_base, files, codes, outfile=None,
msg = verify.compare_code_with_srcfile(infile, outfile, weak_verify=weak_verify) msg = verify.compare_code_with_srcfile(infile, outfile, weak_verify=weak_verify)
if not outfile: if not outfile:
if not msg: if not msg:
print('\n# okay decompiling %s' % infile) print '\n# okay decompiling %s' % infile
okay_files += 1 okay_files += 1
else: else:
print('\n# %s\n\t%s', infile, msg) print '\n# %s\n\t%s', infile, msg
except verify.VerifyCmpError, e: except verify.VerifyCmpError, e:
print(e) print(e)
verify_failed_files += 1 verify_failed_files += 1
@@ -211,7 +211,7 @@ def main(in_base, out_base, files, codes, outfile=None,
if not outfile: if not outfile:
mess = '\n# okay decompiling' mess = '\n# okay decompiling'
# mem_usage = __memUsage() # mem_usage = __memUsage()
print(mess, infile) print mess, infile
if outfile: if outfile:
sys.stdout.write("%s\r" % sys.stdout.write("%s\r" %
status_msg(do_verify, tot_files, okay_files, failed_files, verify_failed_files)) status_msg(do_verify, tot_files, okay_files, failed_files, verify_failed_files))

View File

@@ -13,13 +13,13 @@ import uncompyle6.scanners.scanner21 as scan
from xdis.opcodes import opcode_15 from xdis.opcodes import opcode_15
JUMP_OPs = opcode_15.JUMP_OPs JUMP_OPs = opcode_15.JUMP_OPs
# We base this off of 2.2 instead of the other way around # We base this off of 2.1 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 Scanner15(scan.Scanner21): class Scanner15(scan.Scanner21):
def __init__(self, show_asm=False): def __init__(self, show_asm=False):
scan.Scanner21.__init__(self, show_asm) scan.Scanner21.__init__(self, show_asm=False)
self.opc = opcode_15 self.opc = opcode_15
self.opname = opcode_15.opname self.opname = opcode_15.opname
self.version = 1.5 self.version = 1.5

View File

@@ -19,7 +19,7 @@ JUMP_OPs = opcode_21.JUMP_OPs
# then from that we got 2.6 and so on. # then from that we got 2.6 and so on.
class Scanner21(scan.Scanner22): class Scanner21(scan.Scanner22):
def __init__(self, show_asm=False): def __init__(self, show_asm=False):
scan.Scanner22.__init__(self, show_asm) scan.Scanner22.__init__(self, show_asm=False)
self.opc = opcode_21 self.opc = opcode_21
self.opname = opcode_21.opname self.opname = opcode_21.opname
self.version = 2.1 self.version = 2.1

View File

@@ -19,7 +19,7 @@ JUMP_OPs = opcode_22.JUMP_OPs
# then from that we got 2.6 and so on. # then from that we got 2.6 and so on.
class Scanner22(scan.Scanner23): class Scanner22(scan.Scanner23):
def __init__(self, show_asm=False): def __init__(self, show_asm=False):
scan.Scanner23.__init__(self, show_asm) scan.Scanner23.__init__(self, show_asm=False)
self.opc = opcode_22 self.opc = opcode_22
self.opname = opcode_22.opname self.opname = opcode_22.opname
self.version = 2.2 self.version = 2.2

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

@@ -129,12 +129,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 = {
@@ -542,6 +546,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

@@ -182,16 +182,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