You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
2.7 grammar bug workaround. Fix docstring bug
This commit is contained in:
Binary file not shown.
@@ -49,7 +49,10 @@ class Python27Parser(Python2Parser):
|
||||
|
||||
def p_jump27(self, args):
|
||||
"""
|
||||
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD COME_FROM
|
||||
come_froms ::= come_froms COME_FROM
|
||||
come_froms ::= COME_FROM
|
||||
|
||||
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD come_froms
|
||||
bp_come_from ::= POP_BLOCK COME_FROM
|
||||
|
||||
# FIXME: Common with 3.0+
|
||||
|
@@ -160,7 +160,11 @@ class Scanner2(scan.Scanner):
|
||||
# we sort them). That way, specific COME_FROM tags will match up
|
||||
# properly. For example, a "loop" with an "if" nested in it should have the
|
||||
# "loop" tag last so the grammar rule matches that properly.
|
||||
# last_offset = -1
|
||||
for jump_offset in sorted(jump_targets[offset], reverse=True):
|
||||
# if jump_offset == last_offset:
|
||||
# continue
|
||||
# last_offset = jump_offset
|
||||
come_from_name = 'COME_FROM'
|
||||
opname = self.opc.opname[self.code[jump_offset]]
|
||||
if opname.startswith('SETUP_') and self.version == 2.7:
|
||||
|
@@ -8,12 +8,13 @@ else:
|
||||
maxint = sys.maxint
|
||||
|
||||
def print_docstring(self, indent, docstring):
|
||||
## FIXME: put this into a testable function.
|
||||
if docstring.find('"""') == -1:
|
||||
quote = '"""'
|
||||
else:
|
||||
quote = "'''"
|
||||
|
||||
try:
|
||||
if docstring.find('"""') == -1:
|
||||
quote = '"""'
|
||||
else:
|
||||
quote = "'''"
|
||||
except:
|
||||
return False
|
||||
self.write(indent)
|
||||
if not PYTHON3 and not isinstance(docstring, str):
|
||||
# Must be unicode in Python2
|
||||
@@ -73,6 +74,7 @@ def print_docstring(self, indent, docstring):
|
||||
for line in trimmed[1:-1]:
|
||||
self.println( indent, line )
|
||||
self.println(indent, trimmed[-1], quote)
|
||||
return True
|
||||
|
||||
# if __name__ == '__main__':
|
||||
# if PYTHON3:
|
||||
|
@@ -2120,9 +2120,9 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
docstring = ast[i][0][0][0][0].pattr
|
||||
except:
|
||||
docstring = code.co_consts[0]
|
||||
print_docstring(self, indent, docstring)
|
||||
self.println()
|
||||
del ast[i]
|
||||
if print_docstring(self, indent, docstring):
|
||||
self.println()
|
||||
del ast[i]
|
||||
|
||||
|
||||
# the function defining a class normally returns locals(); we
|
||||
|
Reference in New Issue
Block a user