Skip to content

Commit a92e6c9

Browse files
committed
Bugs in Python 2.6- "and" and "lambda" handling ..
and clean up verify output
1 parent 6c546fe commit a92e6c9

File tree

5 files changed

+30
-9
lines changed

5 files changed

+30
-9
lines changed

test/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ check-bytecode-2.5:
100100

101101
#: Check deparsing Python 2.6
102102
check-bytecode-2.6:
103-
$(PYTHON) test_pythonlib.py --bytecode-2.6
103+
$(PYTHON) test_pythonlib.py --bytecode-2.6 --weak-verify
104104

105105
#: Check deparsing Python 2.7
106106
check-bytecode-2.7:

test/bytecode_2.6/05_ifelse.pyc

-983 Bytes
Binary file not shown.

uncompyle6/main.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,11 +230,11 @@ def status_msg(do_verify, tot_files, okay_files, failed_files,
230230
verify_failed_files):
231231
if tot_files == 1:
232232
if failed_files:
233-
return "decompile failed"
233+
return "\n# decompile failed"
234234
elif verify_failed_files:
235-
return "decompile verify failed"
235+
return "\n# decompile verify failed"
236236
else:
237-
return "Successfully decompiled file"
237+
return "\n# Successfully decompiled file"
238238
pass
239239
pass
240240
mess = "decompiled %i files: %i okay, %i failed" % (tot_files, okay_files, failed_files)

uncompyle6/parsers/parse26.py

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -232,17 +232,37 @@ def p_ret26(self, args):
232232
'''
233233

234234
def p_except26(self, args):
235-
'''
235+
"""
236236
except_suite ::= c_stmts_opt jmp_abs POP_TOP
237-
'''
237+
"""
238238

239239
def p_misc26(self, args):
240-
'''
240+
"""
241241
conditional ::= expr jmp_false expr jf_cf_pop expr come_from_opt
242242
and ::= expr JUMP_IF_FALSE POP_TOP expr JUMP_IF_FALSE POP_TOP
243243
cmp_list ::= expr cmp_list1 ROT_TWO COME_FROM POP_TOP _come_from
244-
'''
245244
245+
conditional_lambda ::= expr jmp_false_then return_if_stmt return_stmt LAMBDA_MARKER
246+
"""
247+
248+
def add_custom_rules(self, tokens, customize):
249+
super(Python26Parser, self).add_custom_rules(tokens, customize)
250+
self.check_reduce['and'] = 'AST'
251+
252+
def reduce_is_invalid(self, rule, ast, tokens, first, last):
253+
invalid = super(Python26Parser,
254+
self).reduce_is_invalid(rule, ast,
255+
tokens, first, last)
256+
if invalid:
257+
return invalid
258+
if rule == ('and', ('expr', 'jmp_false', 'expr', '\\e_come_from_opt')):
259+
# Test that jmp_false jumps to the end of "and"
260+
# or that it jumps to the same place as the end of "and"
261+
jmp_false = ast[1][0]
262+
jmp_target = jmp_false.offset + jmp_false.attr + 3
263+
return not (jmp_target == tokens[last].offset or
264+
tokens[last].pattr == jmp_false.pattr)
265+
return False
246266
class Python26ParserSingle(Python2Parser, PythonParserSingle):
247267
pass
248268

uncompyle6/verify.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,8 @@ def compare_code_with_srcfile(pyc_filename, src_filename, weak_verify=False):
407407
try:
408408
code_obj2 = load_file(src_filename)
409409
except SyntaxError as e:
410-
return str(e)
410+
# src_filename can be the first of a group sometimes
411+
return str(e).replace(src_filename, pyc_filename)
411412
cmp_code_objects(version, is_pypy, code_obj1, code_obj2, ignore_code=weak_verify)
412413
return None
413414

0 commit comments

Comments
 (0)