diff --git a/test/bytecode_2.4/03_iftrue.pyc b/test/bytecode_2.4/03_iftrue.pyc new file mode 100644 index 00000000..7c56fab5 Binary files /dev/null and b/test/bytecode_2.4/03_iftrue.pyc differ diff --git a/uncompyle6/parsers/parse24.py b/uncompyle6/parsers/parse24.py index a178a9d9..8db81f67 100644 --- a/uncompyle6/parsers/parse24.py +++ b/uncompyle6/parsers/parse24.py @@ -32,6 +32,11 @@ class Python24Parser(Python25Parser): importmultiple ::= filler LOAD_CONST alias imports_cont import_cont ::= filler LOAD_CONST alias + # Handle "if true else: ..." in Python 2.4 + stmt ::= iftrue_stmt24 + iftrue_stmt24 ::= _ifstmts_jump24 suite_stmts COME_FROM + _ifstmts_jump24 ::= c_stmts_opt JUMP_FORWARD POP_TOP + # Python 2.5+ omits POP_TOP POP_BLOCK while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_TOP POP_BLOCK COME_FROM while1stmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_TOP POP_BLOCK diff --git a/uncompyle6/semantics/customize.py b/uncompyle6/semantics/customize.py index c54c2f6d..371c9e8b 100644 --- a/uncompyle6/semantics/customize.py +++ b/uncompyle6/semantics/customize.py @@ -43,10 +43,19 @@ def customize_for_version(self, is_pypy, version): 'assert': ( '%|assert %c\n' , 0 ), 'assert2': ( '%|assert %c, %c\n' , 0, 3 ), 'try_except': ( '%|try:\n%+%c%-%c\n\n', 1, 3 ), - 'assign2': ( '%|%c, %c = %c, %c\n', 3, 4, 0, 1 ), - 'assign3': ( '%|%c, %c, %c = %c, %c, %c\n', 5, 6, 7, 0, 1, 2 ), + 'assign2': ( '%|%c, %c = %c, %c\n', + 3, 4, 0, 1 ), + 'assign3': ( '%|%c, %c, %c = %c, %c, %c\n', + 5, 6, 7, 0, 1, 2 ), }) if version < 3.0: + if version == 2.4: + def n_iftrue_stmt24(node): + self.template_engine(('%|%c', 0), node) + self.default(node) + self.prune() + self.n_iftrue_stmt24 = n_iftrue_stmt24 + TABLE_R.update({ 'STORE_SLICE+0': ( '%c[:]', 0 ), 'STORE_SLICE+1': ( '%c[%p:]', 0, (1, -1) ), @@ -62,7 +71,7 @@ def customize_for_version(self, is_pypy, version): }) # exec as a built-in statement is only in Python 2.x - def n_exec_stmt(self, node): + def n_exec_stmt(node): """ exec_stmt ::= expr exprlist DUP_TOP EXEC_STMT exec_stmt ::= expr exprlist EXEC_STMT