You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Fix 2.4/2.5 try/else detection...
in a hacky way
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
# From Python 2.4. test_cgi.py
|
||||
# Bug was in putting try block inside the ifelse statement.
|
||||
|
||||
# Note: this is a self testing program - will assert on failure.
|
||||
def do_test(method):
|
||||
if method == "GET":
|
||||
rc = 0
|
||||
elif method == "POST":
|
||||
rc = 1
|
||||
else:
|
||||
raise ValueError, "unknown method: %s" % method
|
||||
# Bug found in 2.4 test_math.py
|
||||
# Bug was turning last try/except/else into try/else
|
||||
import math
|
||||
def test_exceptions():
|
||||
try:
|
||||
rc = 2
|
||||
except ZeroDivisionError:
|
||||
rc = 3
|
||||
return rc
|
||||
x = math.exp(-1000000000)
|
||||
except:
|
||||
raise RuntimeError
|
||||
|
||||
assert 2 == do_test("GET")
|
||||
try:
|
||||
x = math.sqrt(-1.0)
|
||||
except ValueError:
|
||||
return x
|
||||
else:
|
||||
raise RuntimeError
|
||||
|
||||
test_exceptions()
|
||||
|
@@ -27,7 +27,6 @@ case $PYVERSION in
|
||||
SKIP_TESTS=(
|
||||
[test_dis.py]=1 # We change line numbers - duh!
|
||||
[test_grp.py]=1 # Long test - might work Control flow?
|
||||
[test_math.py]=1 # Control flow?
|
||||
[test_pwd.py]=1 # Long test - might work? Control flow?
|
||||
[test_queue.py]=1 # Control flow?
|
||||
[test_sax.py]=1 # Control flow?
|
||||
@@ -43,7 +42,6 @@ case $PYVERSION in
|
||||
[test_functools.py]=1
|
||||
[test_grammar.py]=1 # Too many stmts. Handle large stmts
|
||||
[test_grp.py]=1 # Long test - might work Control flow?
|
||||
[test_math.py]=1 # Control flow?
|
||||
[test_pdb.py]=1
|
||||
[test_pwd.py]=1 # Long test - might work? Control flow?
|
||||
[test_queue.py]=1 # Control flow?
|
||||
|
@@ -81,14 +81,27 @@ class Python25Parser(Python26Parser):
|
||||
""")
|
||||
super(Python25Parser, self).customize_grammar_rules(tokens, customize)
|
||||
if self.version == 2.5:
|
||||
self.check_reduce['tryelsestmt'] = 'tokens'
|
||||
self.check_reduce['try_except'] = 'tokens'
|
||||
|
||||
def reduce_is_invalid(self, rule, ast, tokens, first, last):
|
||||
invalid = super(Python25Parser,
|
||||
self).reduce_is_invalid(rule, ast,
|
||||
tokens, first, last)
|
||||
if invalid:
|
||||
if invalid or tokens is None:
|
||||
return invalid
|
||||
elif rule[0] == 'try_except':
|
||||
# Distinguish try/except from try/except/else
|
||||
if last == len(tokens):
|
||||
last -= 1
|
||||
if tokens[last] != 'COME_FROM' and tokens[last-1] == 'COME_FROM':
|
||||
last -= 1
|
||||
if (tokens[last] == 'COME_FROM'
|
||||
and tokens[last-1] == 'END_FINALLY'
|
||||
and tokens[last-2] == 'POP_TOP'):
|
||||
# A jump of 2 is a jump around POP_TOP, END_FINALLY which
|
||||
# would indicate try/else rather than try
|
||||
return (tokens[last-3].kind != 'JUMP_FORWARD'
|
||||
or tokens[last-3].attr != 2)
|
||||
return False
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user