You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
Start Python3 execption handling
This commit is contained in:
BIN
test/bytecode_2.7/01_try_except.pyc
Normal file
BIN
test/bytecode_2.7/01_try_except.pyc
Normal file
Binary file not shown.
@@ -1 +1,8 @@
|
||||
These are byte-compiled programs compiled by Python 2.7
|
||||
|
||||
The numbers in the filenames are to assist running the programs from
|
||||
the simplest to more complex. For example, many tests have assignment
|
||||
statements or function calls, so we want to test those constructs
|
||||
first.
|
||||
|
||||
Code and organization merged from uncompyle3, uncompyle{,2}, and pycdc
|
||||
|
8
test/bytecode_3.2/README
Normal file
8
test/bytecode_3.2/README
Normal file
@@ -0,0 +1,8 @@
|
||||
These are byte-compiled programs compiled by Python 3.2
|
||||
|
||||
The numbers in the filenames are to assist running the programs from
|
||||
the simplest to more complex. For example, many tests have assignment
|
||||
statements or function calls, so we want to test those constructs
|
||||
first.
|
||||
|
||||
Code and organization merged from uncompyle3, uncompyle{,2}, and pycdc
|
BIN
test/bytecode_3.4/00_assign.pyc
Normal file
BIN
test/bytecode_3.4/00_assign.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.4/01_try_except.pyc
Normal file
BIN
test/bytecode_3.4/01_try_except.pyc
Normal file
Binary file not shown.
@@ -1 +1,8 @@
|
||||
These are byte-compiled programs compiled by Python 3.4
|
||||
|
||||
The numbers in the filenames are to assist running the programs from
|
||||
the simplest to more complex. For example, many tests have assignment
|
||||
statements or function calls, so we want to test those constructs
|
||||
first.
|
||||
|
||||
Code and organization merged from uncompyle3, uncompyle{,2}, and pycdc
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -55,12 +55,12 @@ tests['2.3'] = tests['2.2']
|
||||
tests['2.5'] = tests['2.3']
|
||||
# tests['2.7'] = ['mine'] + tests['2.6']
|
||||
tests['2.7'] = [
|
||||
# 'simple-source/branching/ifelse',
|
||||
# 'simple-source/branching/if'
|
||||
'simple-source/misc/assert',
|
||||
'simple-source/misc/assign',
|
||||
# 'simple-source/call_arguments/keyword',
|
||||
# 'simple-source/call_arguments/positional'
|
||||
# 'simple_source/branching/ifelse',
|
||||
# 'simple_source/branching/if'
|
||||
'simple_source/misc/assert',
|
||||
'simple_source/misc/assign',
|
||||
# 'simple_source/call_arguments/keyword',
|
||||
# 'simple_source/call_arguments/positional'
|
||||
]
|
||||
tests['2.6'] = tests['2.7']
|
||||
|
||||
@@ -71,9 +71,9 @@ def file_matches(files, root, basenames, patterns):
|
||||
if fnmatch(n, pat)])
|
||||
|
||||
PY = ('*.py', )
|
||||
files = ['simple-source']
|
||||
files = ['simple_source']
|
||||
simple_source = []
|
||||
for root, dirs, basenames in os.walk('simple-source'):
|
||||
for root, dirs, basenames in os.walk('simple_source'):
|
||||
for basename in basenames:
|
||||
if basename.endswith('.py'):
|
||||
simple_source.append(os.path.join(root, basename)[0:-3])
|
||||
|
@@ -4,4 +4,9 @@ across all versions of Python.
|
||||
Their simnplicity is to try to make it easier to debug grammar
|
||||
and AST walking routines.
|
||||
|
||||
This code originally taken from https://github.com/DarkFenX/uncompyle3
|
||||
The numbers in the filenames are to assist running the programs from
|
||||
the simplest to more complex. For example, many tests have assignment
|
||||
statements or function calls, so we want to test those constructs
|
||||
first.
|
||||
|
||||
Code and organization merged from uncompyle3, uncompyle{,2}, and pycdc
|
||||
|
@@ -1,4 +1,27 @@
|
||||
# Tests:
|
||||
# trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||
# try_middle COME_FROM
|
||||
# except_stmt ::= except
|
||||
|
||||
try:
|
||||
x = 1
|
||||
except:
|
||||
pass
|
||||
|
||||
# Tests:
|
||||
# trystmt ::= SETUP_EXCEPT suite_stmts_opt POP_BLOCK
|
||||
# try_middle COME_FROM
|
||||
# except_stmt ::= except_cond1 except_suite
|
||||
# except_suite ::= ...
|
||||
|
||||
try:
|
||||
x = 1
|
||||
except ImportError:
|
||||
pass
|
||||
|
||||
try:
|
||||
x = 2
|
||||
except ImportError:
|
||||
x = 3
|
||||
finally:
|
||||
x = 4
|
||||
|
@@ -1 +0,0 @@
|
||||
vario = 'None'
|
@@ -1,4 +1,6 @@
|
||||
# Tests:
|
||||
# assign ::= expr designator
|
||||
|
||||
vario = 556
|
||||
a = 'None'
|
||||
b = None
|
||||
c = 556
|
@@ -441,18 +441,19 @@ class Python3Parser(PythonParser):
|
||||
except_stmt ::= except_cond2 except_suite
|
||||
except_stmt ::= except
|
||||
|
||||
except_suite ::= c_stmts_opt JUMP_FORWARD
|
||||
except_suite ::= c_stmts_opt jmp_abs
|
||||
except_suite ::= c_stmts_opt POP_EXCEPT JUMP_FORWARD
|
||||
except_suite ::= c_stmts_opt POP_EXCEPT jmp_abs
|
||||
except_suite ::= return_stmts
|
||||
|
||||
except_cond1 ::= DUP_TOP expr COMPARE_OP
|
||||
jmp_false POP_TOP POP_TOP POP_TOP
|
||||
|
||||
except_cond2 ::= DUP_TOP expr COMPARE_OP
|
||||
jmp_false POP_TOP designator POP_TOP
|
||||
jmp_false POP_TOP designator
|
||||
|
||||
except ::= POP_TOP POP_TOP POP_TOP POP_EXCEPT c_stmts_opt JUMP_FORWARD
|
||||
except ::= POP_TOP POP_TOP POP_TOP c_stmts_opt JUMP_FORWARD
|
||||
except ::= POP_TOP POP_TOP POP_TOP c_stmts_opt jmp_abs
|
||||
except ::= POP_TOP POP_TOP POP_TOP POP_EXCEPT c_stmts_opt jmp_abs
|
||||
except ::= POP_TOP POP_TOP POP_TOP return_stmts
|
||||
|
||||
jmp_abs ::= JUMP_ABSOLUTE
|
||||
|
@@ -314,7 +314,6 @@ TABLE_DIRECT = {
|
||||
'tryelsestmtl': ( '%|try:\n%+%c%-%c%|else:\n%+%c%-', 1, 3, 4 ),
|
||||
'tf_trystmt': ( '%c%-%c%+', 1, 3 ),
|
||||
'tf_tryelsestmt': ( '%c%-%c%|else:\n%+%c', 1, 3, 4 ),
|
||||
'except': ( '%|except:\n%+%c%-', 3 ),
|
||||
'except_cond1': ( '%|except %c:\n', 1 ),
|
||||
'except_cond2': ( '%|except %c as %c:\n', 1, 5 ),
|
||||
'except_suite': ( '%+%c%-%C', 0, (1, maxint, '') ),
|
||||
@@ -490,6 +489,14 @@ class Walker(GenericASTTraversal, object):
|
||||
self.currentclass = None
|
||||
self.pending_newlines = 0
|
||||
|
||||
if version >= 3.0:
|
||||
# Python 3 adds a POP_EXCEPT instruction
|
||||
TABLE_DIRECT['except'] = ('%|except:\n%+%c%-', 4 )
|
||||
else:
|
||||
TABLE_DIRECT['except'] = ('%|except:\n%+%c%-', 3 )
|
||||
pass
|
||||
return
|
||||
|
||||
f = property(lambda s: s.params['f'],
|
||||
lambda s, x: s.params.__setitem__('f', x),
|
||||
lambda s: s.params.__delitem__('f'),
|
||||
@@ -1184,6 +1191,9 @@ class Walker(GenericASTTraversal, object):
|
||||
# self.print_("-----")
|
||||
# self.print(startnode)
|
||||
|
||||
# from trepan.api import debug
|
||||
# debug(start_opts={'startup-profile': True})
|
||||
|
||||
fmt = entry[0]
|
||||
arg = 1
|
||||
i = 0
|
||||
|
Reference in New Issue
Block a user