You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Add flag to tolerate deparse errors...
and keep going. The fragment parser should ignore errors in nested function definitions
This commit is contained in:
@@ -114,11 +114,12 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
|
||||
def __init__(self, version, scanner, showast=False,
|
||||
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(),
|
||||
scanner=scanner,
|
||||
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
|
||||
# exist in code but but were not written in the source code.
|
||||
|
@@ -8,6 +8,7 @@ from uncompyle6.scanner import Code
|
||||
from uncompyle6.parsers.astnode import AST
|
||||
from uncompyle6 import PYTHON3
|
||||
from uncompyle6.semantics.parser_error import ParserError
|
||||
from uncompyle6.parser import ParserError as ParserError2
|
||||
from uncompyle6.semantics.helper import print_docstring
|
||||
|
||||
if PYTHON3:
|
||||
@@ -128,9 +129,10 @@ def make_function3_annotate(self, node, isLambda, nested=1,
|
||||
code._customize,
|
||||
isLambda = isLambda,
|
||||
noneInNames = ('None' in code.co_names))
|
||||
except ParserError as p:
|
||||
except (ParserError, ParserError2) as p:
|
||||
self.write(str(p))
|
||||
self.ERROR = p
|
||||
if not self.tolerate_errors:
|
||||
self.ERROR = p
|
||||
return
|
||||
|
||||
kw_pairs = args_node.attr[1]
|
||||
@@ -356,9 +358,10 @@ def make_function2(self, node, isLambda, nested=1, codeNode=None):
|
||||
code._customize,
|
||||
isLambda = isLambda,
|
||||
noneInNames = ('None' in code.co_names))
|
||||
except ParserError as p:
|
||||
except (ParserError, ParserError2) as p:
|
||||
self.write(str(p))
|
||||
self.ERROR = p
|
||||
if not self.tolerate_errors:
|
||||
self.ERROR = p
|
||||
return
|
||||
|
||||
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,
|
||||
isLambda = isLambda,
|
||||
noneInNames = ('None' in code.co_names))
|
||||
except ParserError as p:
|
||||
except (ParserError, ParserError2) as p:
|
||||
self.write(str(p))
|
||||
self.ERROR = p
|
||||
if not self.tolerate_errors:
|
||||
self.ERROR = p
|
||||
return
|
||||
|
||||
kw_pairs = args_node.attr[1] if self.version >= 3.0 else 0
|
||||
|
@@ -166,7 +166,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
def __init__(self, version, out, scanner, showast=False,
|
||||
debug_parser=PARSER_DEFAULT_DEBUG,
|
||||
compile_mode='exec', is_pypy=False,
|
||||
linestarts={}):
|
||||
linestarts={}, tolerate_errors=False):
|
||||
"""version is the Python version (a float) of the Python dialect
|
||||
|
||||
of both the AST and language we should produce.
|
||||
@@ -214,6 +214,10 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.line_number = 0
|
||||
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
|
||||
# exist in code but but were not written in the source code.
|
||||
# An example is:
|
||||
|
Reference in New Issue
Block a user