You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Merge branch 'python-2.4' of github.com:rocky/python-uncompyle6 into python-2.4
This commit is contained in:
Binary file not shown.
@@ -1,18 +1,17 @@
|
|||||||
# From Python 2.4. test_cgi.py
|
# Bug found in 2.4 test_math.py
|
||||||
# Bug was in putting try block inside the ifelse statement.
|
# Bug was turning last try/except/else into try/else
|
||||||
|
import math
|
||||||
# Note: this is a self testing program - will assert on failure.
|
def test_exceptions():
|
||||||
def do_test(method):
|
|
||||||
if method == "GET":
|
|
||||||
rc = 0
|
|
||||||
elif method == "POST":
|
|
||||||
rc = 1
|
|
||||||
else:
|
|
||||||
raise ValueError, "unknown method: %s" % method
|
|
||||||
try:
|
try:
|
||||||
rc = 2
|
x = math.exp(-1000000000)
|
||||||
except ZeroDivisionError:
|
except:
|
||||||
rc = 3
|
raise RuntimeError
|
||||||
return rc
|
|
||||||
|
|
||||||
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=(
|
SKIP_TESTS=(
|
||||||
[test_dis.py]=1 # We change line numbers - duh!
|
[test_dis.py]=1 # We change line numbers - duh!
|
||||||
[test_grp.py]=1 # Long test - might work Control flow?
|
[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_pwd.py]=1 # Long test - might work? Control flow?
|
||||||
[test_queue.py]=1 # Control flow?
|
[test_queue.py]=1 # Control flow?
|
||||||
[test_sax.py]=1 # Control flow?
|
[test_sax.py]=1 # Control flow?
|
||||||
@@ -43,7 +42,6 @@ case $PYVERSION in
|
|||||||
[test_functools.py]=1
|
[test_functools.py]=1
|
||||||
[test_grammar.py]=1 # Too many stmts. Handle large stmts
|
[test_grammar.py]=1 # Too many stmts. Handle large stmts
|
||||||
[test_grp.py]=1 # Long test - might work Control flow?
|
[test_grp.py]=1 # Long test - might work Control flow?
|
||||||
[test_math.py]=1 # Control flow?
|
|
||||||
[test_pdb.py]=1
|
[test_pdb.py]=1
|
||||||
[test_pwd.py]=1 # Long test - might work? Control flow?
|
[test_pwd.py]=1 # Long test - might work? Control flow?
|
||||||
[test_queue.py]=1 # Control flow?
|
[test_queue.py]=1 # Control flow?
|
||||||
|
@@ -69,7 +69,6 @@ class Python24Parser(Python25Parser):
|
|||||||
super(Python24Parser, self).customize_grammar_rules(tokens, customize)
|
super(Python24Parser, self).customize_grammar_rules(tokens, customize)
|
||||||
if self.version == 2.4:
|
if self.version == 2.4:
|
||||||
self.check_reduce['nop_stmt'] = 'tokens'
|
self.check_reduce['nop_stmt'] = 'tokens'
|
||||||
self.check_reduce['try_except'] = 'tokens'
|
|
||||||
|
|
||||||
def reduce_is_invalid(self, rule, ast, tokens, first, last):
|
def reduce_is_invalid(self, rule, ast, tokens, first, last):
|
||||||
invalid = super(Python24Parser,
|
invalid = super(Python24Parser,
|
||||||
@@ -83,15 +82,6 @@ class Python24Parser(Python25Parser):
|
|||||||
l = len(tokens)
|
l = len(tokens)
|
||||||
if 0 <= l < len(tokens):
|
if 0 <= l < len(tokens):
|
||||||
return not int(tokens[first].pattr) == tokens[last].offset
|
return not int(tokens[first].pattr) == tokens[last].offset
|
||||||
elif lhs == 'try_except':
|
|
||||||
if last == len(tokens):
|
|
||||||
last -= 1
|
|
||||||
if tokens[last] != 'COME_FROM' and tokens[last-1] == 'COME_FROM':
|
|
||||||
last -= 1
|
|
||||||
return (tokens[last] == 'COME_FROM'
|
|
||||||
and tokens[last-1] == 'END_FINALLY'
|
|
||||||
and tokens[last-2] == 'POP_TOP'
|
|
||||||
and tokens[last-3].kind != 'JUMP_FORWARD')
|
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@@ -89,14 +89,27 @@ class Python25Parser(Python26Parser):
|
|||||||
""")
|
""")
|
||||||
super(Python25Parser, self).customize_grammar_rules(tokens, customize)
|
super(Python25Parser, self).customize_grammar_rules(tokens, customize)
|
||||||
if self.version == 2.5:
|
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):
|
def reduce_is_invalid(self, rule, ast, tokens, first, last):
|
||||||
invalid = super(Python25Parser,
|
invalid = super(Python25Parser,
|
||||||
self).reduce_is_invalid(rule, ast,
|
self).reduce_is_invalid(rule, ast,
|
||||||
tokens, first, last)
|
tokens, first, last)
|
||||||
if invalid:
|
if invalid or tokens is None:
|
||||||
return invalid
|
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
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user