Add flag to tolerate deparse errors...

and keep going. The fragment parser should ignore errors
in nested function definitions
This commit is contained in:
rocky
2017-11-04 12:29:27 -04:00
parent 6746e5167d
commit 4f0a668b7c
3 changed files with 18 additions and 9 deletions

View File

@@ -114,11 +114,12 @@ class FragmentsWalker(pysource.SourceWalker, object):
def __init__(self, version, scanner, showast=False, def __init__(self, version, scanner, showast=False,
debug_parser=PARSER_DEFAULT_DEBUG, debug_parser=PARSER_DEFAULT_DEBUG,
compile_mode='exec', is_pypy=False): compile_mode='exec', is_pypy=False, tolerate_errors=True):
pysource.SourceWalker.__init__(self, version=version, out=StringIO(), pysource.SourceWalker.__init__(self, version=version, out=StringIO(),
scanner=scanner, scanner=scanner,
showast=showast, debug_parser=debug_parser, showast=showast, debug_parser=debug_parser,
compile_mode=compile_mode, is_pypy=is_pypy) compile_mode=compile_mode, is_pypy=is_pypy,
tolerate_errors=tolerate_errors)
# hide_internal suppresses displaying the additional instructions that sometimes # hide_internal suppresses displaying the additional instructions that sometimes
# exist in code but but were not written in the source code. # exist in code but but were not written in the source code.

View File

@@ -8,6 +8,7 @@ from uncompyle6.scanner import Code
from uncompyle6.parsers.astnode import AST from uncompyle6.parsers.astnode import AST
from uncompyle6 import PYTHON3 from uncompyle6 import PYTHON3
from uncompyle6.semantics.parser_error import ParserError from uncompyle6.semantics.parser_error import ParserError
from uncompyle6.parser import ParserError as ParserError2
from uncompyle6.semantics.helper import print_docstring from uncompyle6.semantics.helper import print_docstring
if PYTHON3: if PYTHON3:
@@ -128,9 +129,10 @@ def make_function3_annotate(self, node, isLambda, nested=1,
code._customize, code._customize,
isLambda = isLambda, isLambda = isLambda,
noneInNames = ('None' in code.co_names)) noneInNames = ('None' in code.co_names))
except ParserError as p: except (ParserError, ParserError2) as p:
self.write(str(p)) self.write(str(p))
self.ERROR = p if not self.tolerate_errors:
self.ERROR = p
return return
kw_pairs = args_node.attr[1] kw_pairs = args_node.attr[1]
@@ -356,9 +358,10 @@ def make_function2(self, node, isLambda, nested=1, codeNode=None):
code._customize, code._customize,
isLambda = isLambda, isLambda = isLambda,
noneInNames = ('None' in code.co_names)) noneInNames = ('None' in code.co_names))
except ParserError as p: except (ParserError, ParserError2) as p:
self.write(str(p)) self.write(str(p))
self.ERROR = p if not self.tolerate_errors:
self.ERROR = p
return return
kw_pairs = args_node.attr[1] if self.version >= 3.0 else 0 kw_pairs = args_node.attr[1] if self.version >= 3.0 else 0
@@ -531,9 +534,10 @@ def make_function3(self, node, isLambda, nested=1, codeNode=None):
code._customize, code._customize,
isLambda = isLambda, isLambda = isLambda,
noneInNames = ('None' in code.co_names)) noneInNames = ('None' in code.co_names))
except ParserError as p: except (ParserError, ParserError2) as p:
self.write(str(p)) self.write(str(p))
self.ERROR = p if not self.tolerate_errors:
self.ERROR = p
return return
kw_pairs = args_node.attr[1] if self.version >= 3.0 else 0 kw_pairs = args_node.attr[1] if self.version >= 3.0 else 0

View File

@@ -166,7 +166,7 @@ class SourceWalker(GenericASTTraversal, object):
def __init__(self, version, out, scanner, showast=False, def __init__(self, version, out, scanner, showast=False,
debug_parser=PARSER_DEFAULT_DEBUG, debug_parser=PARSER_DEFAULT_DEBUG,
compile_mode='exec', is_pypy=False, compile_mode='exec', is_pypy=False,
linestarts={}): linestarts={}, tolerate_errors=False):
"""version is the Python version (a float) of the Python dialect """version is the Python version (a float) of the Python dialect
of both the AST and language we should produce. of both the AST and language we should produce.
@@ -214,6 +214,10 @@ class SourceWalker(GenericASTTraversal, object):
self.line_number = 0 self.line_number = 0
self.ast_errors = [] self.ast_errors = []
# Sometimes we may want to continue decompiling when there are errors
# and sometimes not
self.tolerate_errors = tolerate_errors
# hide_internal suppresses displaying the additional instructions that sometimes # hide_internal suppresses displaying the additional instructions that sometimes
# exist in code but but were not written in the source code. # exist in code but but were not written in the source code.
# An example is: # An example is: