You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +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):
|
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
|
bp_come_from ::= POP_BLOCK COME_FROM
|
||||||
|
|
||||||
# FIXME: Common with 3.0+
|
# 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
|
# 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
|
# properly. For example, a "loop" with an "if" nested in it should have the
|
||||||
# "loop" tag last so the grammar rule matches that properly.
|
# "loop" tag last so the grammar rule matches that properly.
|
||||||
|
# last_offset = -1
|
||||||
for jump_offset in sorted(jump_targets[offset], reverse=True):
|
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'
|
come_from_name = 'COME_FROM'
|
||||||
opname = self.opc.opname[self.code[jump_offset]]
|
opname = self.opc.opname[self.code[jump_offset]]
|
||||||
if opname.startswith('SETUP_') and self.version == 2.7:
|
if opname.startswith('SETUP_') and self.version == 2.7:
|
||||||
|
@@ -8,12 +8,13 @@ else:
|
|||||||
maxint = sys.maxint
|
maxint = sys.maxint
|
||||||
|
|
||||||
def print_docstring(self, indent, docstring):
|
def print_docstring(self, indent, docstring):
|
||||||
## FIXME: put this into a testable function.
|
try:
|
||||||
if docstring.find('"""') == -1:
|
if docstring.find('"""') == -1:
|
||||||
quote = '"""'
|
quote = '"""'
|
||||||
else:
|
else:
|
||||||
quote = "'''"
|
quote = "'''"
|
||||||
|
except:
|
||||||
|
return False
|
||||||
self.write(indent)
|
self.write(indent)
|
||||||
if not PYTHON3 and not isinstance(docstring, str):
|
if not PYTHON3 and not isinstance(docstring, str):
|
||||||
# Must be unicode in Python2
|
# Must be unicode in Python2
|
||||||
@@ -73,6 +74,7 @@ def print_docstring(self, indent, docstring):
|
|||||||
for line in trimmed[1:-1]:
|
for line in trimmed[1:-1]:
|
||||||
self.println( indent, line )
|
self.println( indent, line )
|
||||||
self.println(indent, trimmed[-1], quote)
|
self.println(indent, trimmed[-1], quote)
|
||||||
|
return True
|
||||||
|
|
||||||
# if __name__ == '__main__':
|
# if __name__ == '__main__':
|
||||||
# if PYTHON3:
|
# if PYTHON3:
|
||||||
|
@@ -2120,9 +2120,9 @@ class SourceWalker(GenericASTTraversal, object):
|
|||||||
docstring = ast[i][0][0][0][0].pattr
|
docstring = ast[i][0][0][0][0].pattr
|
||||||
except:
|
except:
|
||||||
docstring = code.co_consts[0]
|
docstring = code.co_consts[0]
|
||||||
print_docstring(self, indent, docstring)
|
if print_docstring(self, indent, docstring):
|
||||||
self.println()
|
self.println()
|
||||||
del ast[i]
|
del ast[i]
|
||||||
|
|
||||||
|
|
||||||
# the function defining a class normally returns locals(); we
|
# the function defining a class normally returns locals(); we
|
||||||
|
Reference in New Issue
Block a user