diff --git a/test/bytecode_2.7/02_ifelsetmtl.pyc b/test/bytecode_2.7/02_ifelsetmtl.pyc new file mode 100644 index 00000000..fd580645 Binary files /dev/null and b/test/bytecode_2.7/02_ifelsetmtl.pyc differ diff --git a/test/simple_source/bug27+/02_ifelsetmtl.py b/test/simple_source/bug27+/02_ifelsetmtl.py new file mode 100644 index 00000000..72fb520b --- /dev/null +++ b/test/simple_source/bug27+/02_ifelsetmtl.py @@ -0,0 +1,11 @@ +# Issue #148 on 2.7 +# Bug is in handling CONTINUE like JUMP_BACK +# Similar code is probably found in a 2.7 stdlib. mapurl? +def reduce_url(url): + atoms = [] + for atom in url: + if atom == '.': + pass # JUMP_BACK is patched as CONTINUE here + elif atom == '..': + atoms.push() + return atoms diff --git a/uncompyle6/main.py b/uncompyle6/main.py index 9fa1e2d7..4da6c2f6 100644 --- a/uncompyle6/main.py +++ b/uncompyle6/main.py @@ -1,7 +1,7 @@ from __future__ import print_function import datetime, os, subprocess, sys, tempfile -from uncompyle6 import verify, IS_PYPY +from uncompyle6 import verify, IS_PYPY, PYTHON_VERSION from xdis.code import iscode from uncompyle6.disas import check_object_path from uncompyle6.semantics import pysource @@ -156,10 +156,15 @@ def main(in_base, out_base, files, codes, outfile=None, # Unbuffer output if possible buffering = -1 if sys.stdout.isatty() else 0 - t = tempfile.NamedTemporaryFile(mode='w+b', - buffering=buffering, - suffix='.py', - prefix=prefix) + if PYTHON_VERSION >= 3.5: + t = tempfile.NamedTemporaryFile(mode='w+b', + buffering=buffering, + suffix='.py', + prefix=prefix) + else: + t = tempfile.NamedTemporaryFile(mode='w+b', + suffix='.py', + prefix=prefix) current_outfile = t.name sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', buffering) tee = subprocess.Popen(["tee", current_outfile], diff --git a/uncompyle6/parsers/parse27.py b/uncompyle6/parsers/parse27.py index fd59eff2..37abf587 100644 --- a/uncompyle6/parsers/parse27.py +++ b/uncompyle6/parsers/parse27.py @@ -131,6 +131,7 @@ class Python27Parser(Python2Parser): ifelsestmt ::= testexpr c_stmts_opt JUMP_FORWARD else_suite COME_FROM ifelsestmtc ::= testexpr c_stmts_opt JUMP_ABSOLUTE else_suitec ifelsestmtl ::= testexpr c_stmts_opt JUMP_BACK else_suitel + ifelsestmtl ::= testexpr c_stmts_opt CONTINUE else_suitel # Common with 2.6 return_if_lambda ::= RETURN_END_IF_LAMBDA COME_FROM diff --git a/uncompyle6/scanners/scanner27.py b/uncompyle6/scanners/scanner27.py index 377a27e8..ee571067 100755 --- a/uncompyle6/scanners/scanner27.py +++ b/uncompyle6/scanners/scanner27.py @@ -1,4 +1,4 @@ -# Copyright (c) 2015-2017 by Rocky Bernstein +# Copyright (c) 2015-2018 by Rocky Bernstein """ Python 2.7 bytecode ingester.