You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Walker->SourceWalker Traverser->FragmentsWalker
This commit is contained in:
@@ -29,7 +29,7 @@ def uncompyle(version, co, out=None, showasm=False, showast=False,
|
|||||||
try:
|
try:
|
||||||
pysource.deparse_code(version, co, out, showasm, showast, showgrammar,
|
pysource.deparse_code(version, co, out, showasm, showast, showgrammar,
|
||||||
code_objects=code_objects)
|
code_objects=code_objects)
|
||||||
except pysource.WalkerError as e:
|
except pysource.SourceWalkerError as e:
|
||||||
# deparsing failed
|
# deparsing failed
|
||||||
if real_out != out:
|
if real_out != out:
|
||||||
print(e, file=real_out)
|
print(e, file=real_out)
|
||||||
|
@@ -67,7 +67,7 @@ TABLE_DIRECT_FRAGMENT = {
|
|||||||
# '%|for %c%x in %c:\n%+%c%-%|else:\n%+%c%-\n\n', 3, (3, (2,)), 1, 4, -2),
|
# '%|for %c%x in %c:\n%+%c%-%|else:\n%+%c%-\n\n', 3, (3, (2,)), 1, 4, -2),
|
||||||
}
|
}
|
||||||
|
|
||||||
class Traverser(pysource.Walker, object):
|
class FragmentsWalker(pysource.SourceWalker, object):
|
||||||
stacked_params = ('f', 'indent', 'isLambda', '_globals')
|
stacked_params = ('f', 'indent', 'isLambda', '_globals')
|
||||||
|
|
||||||
def __init__(self, version, scanner, showast=False,
|
def __init__(self, version, scanner, showast=False,
|
||||||
@@ -1260,8 +1260,8 @@ def deparse_code(version, co, out=StringIO(), showasm=False, showast=False,
|
|||||||
debug_parser['reduce'] = showgrammar
|
debug_parser['reduce'] = showgrammar
|
||||||
|
|
||||||
# Build AST from disassembly.
|
# Build AST from disassembly.
|
||||||
# deparsed = pysource.Walker(out, scanner, showast=showast)
|
# deparsed = pysource.FragmentsWalker(out, scanner, showast=showast)
|
||||||
deparsed = Traverser(version, scanner, showast=showast, debug_parser=debug_parser)
|
deparsed = FragmentsWalker(version, scanner, showast=showast, debug_parser=debug_parser)
|
||||||
|
|
||||||
deparsed.ast = deparsed.build_ast(tokens, customize)
|
deparsed.ast = deparsed.build_ast(tokens, customize)
|
||||||
|
|
||||||
@@ -1336,5 +1336,5 @@ if __name__ == '__main__':
|
|||||||
# check_args(['3', '5'])
|
# check_args(['3', '5'])
|
||||||
deparse_test(get_code_for_fn(gcd))
|
deparse_test(get_code_for_fn(gcd))
|
||||||
# deparse_test(get_code_for_fn(gcd))
|
# deparse_test(get_code_for_fn(gcd))
|
||||||
# deparse_test(get_code_for_fn(Traverser.fixup_offsets))
|
# deparse_test(get_code_for_fn(FragmentsWalker.fixup_offsets))
|
||||||
# deparse_test(inspect.currentframe().f_code)
|
# deparse_test(inspect.currentframe().f_code)
|
||||||
|
@@ -472,14 +472,14 @@ def find_none(node):
|
|||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
class WalkerError(Exception):
|
class SourceWalkerError(Exception):
|
||||||
def __init__(self, errmsg):
|
def __init__(self, errmsg):
|
||||||
self.errmsg = errmsg
|
self.errmsg = errmsg
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return self.errmsg
|
return self.errmsg
|
||||||
|
|
||||||
class Walker(GenericASTTraversal, object):
|
class SourceWalker(GenericASTTraversal, object):
|
||||||
stacked_params = ('f', 'indent', 'isLambda', '_globals')
|
stacked_params = ('f', 'indent', 'isLambda', '_globals')
|
||||||
|
|
||||||
def __init__(self, version, out, scanner, showast=False,
|
def __init__(self, version, out, scanner, showast=False,
|
||||||
@@ -1632,7 +1632,7 @@ def deparse_code(version, co, out=sys.stdout, showasm=False, showast=False,
|
|||||||
debug_parser['reduce'] = showgrammar
|
debug_parser['reduce'] = showgrammar
|
||||||
|
|
||||||
# Build AST from disassembly.
|
# Build AST from disassembly.
|
||||||
deparsed = Walker(version, out, scanner, showast=showast, debug_parser=debug_parser)
|
deparsed = SourceWalker(version, out, scanner, showast=showast, debug_parser=debug_parser)
|
||||||
|
|
||||||
deparsed.ast = deparsed.build_ast(tokens, customize)
|
deparsed.ast = deparsed.build_ast(tokens, customize)
|
||||||
|
|
||||||
@@ -1660,7 +1660,7 @@ def deparse_code(version, co, out=sys.stdout, showasm=False, showast=False,
|
|||||||
deparsed.write('# global %s ## Warning: Unused global' % g)
|
deparsed.write('# global %s ## Warning: Unused global' % g)
|
||||||
|
|
||||||
if deparsed.ERROR:
|
if deparsed.ERROR:
|
||||||
raise WalkerError("Deparsing stopped due to parse error")
|
raise SourceWalkerError("Deparsing stopped due to parse error")
|
||||||
return deparsed
|
return deparsed
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Reference in New Issue
Block a user