You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Handle Python 2.6 and below "except <cond>, <var>"
This commit is contained in:
BIN
test/bytecode_2.5/02_except_as.pyc
Normal file
BIN
test/bytecode_2.5/02_except_as.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.6/02_except_as.pyc
Normal file
BIN
test/bytecode_2.6/02_except_as.pyc
Normal file
Binary file not shown.
18
test/simple_source/bug26/02_except_as.py
Normal file
18
test/simple_source/bug26/02_except_as.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# From 2.6.9 ConfigParser.py
|
||||
# Bug was being able to handle:
|
||||
# except KeyError, e
|
||||
# vs 2.6+.
|
||||
# except KeyError as e
|
||||
#
|
||||
# In terms of table syntax:
|
||||
# 2.7+:
|
||||
# 'except_cond2': ( '%|except %c as %c:\n', 1, 5 )
|
||||
# vs 2.6 and before
|
||||
# 'except_cond3': ( '%|except %c, %c:\n', 1, 6 )
|
||||
#
|
||||
# Python 2.6 allows both, but we use the older form since
|
||||
# that matches the grammar for how this gets parsed
|
||||
try:
|
||||
value = "foo"
|
||||
except KeyError, e:
|
||||
raise RuntimeError('foo')
|
@@ -16,9 +16,10 @@ class Python26Parser(Python2Parser):
|
||||
|
||||
def p_try_except26(self, args):
|
||||
"""
|
||||
except_stmt ::= except_cond3 except_suite
|
||||
except_cond1 ::= DUP_TOP expr COMPARE_OP
|
||||
JUMP_IF_FALSE POP_TOP POP_TOP POP_TOP POP_TOP
|
||||
except_cond2 ::= DUP_TOP expr COMPARE_OP
|
||||
except_cond3 ::= DUP_TOP expr COMPARE_OP
|
||||
JUMP_IF_FALSE POP_TOP POP_TOP designator POP_TOP
|
||||
|
||||
# Might be a bug from when COME_FROM wasn't properly handled
|
||||
|
@@ -319,7 +319,6 @@ TABLE_DIRECT = {
|
||||
'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 5 ),
|
||||
'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, '') ),
|
||||
'except_suite_finalize': ( '%+%c%-%C', 1, (3, maxint, '') ),
|
||||
'withstmt': ( '%|with %c:\n%+%c%-', 0, 3),
|
||||
@@ -580,6 +579,25 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
'import_cont' : ( ', %c', 2 ),
|
||||
})
|
||||
|
||||
########################################
|
||||
# Python 2.6+
|
||||
# except <condition> as <var>
|
||||
# vs. older:
|
||||
# except <condition> , <var>
|
||||
#
|
||||
# For 2.6 we use the older syntax which
|
||||
# matches how we parse this in bytecode
|
||||
########################################
|
||||
if version > 2.6:
|
||||
TABLE_DIRECT.update({
|
||||
'except_cond2': ( '%|except %c as %c:\n', 1, 5 ),
|
||||
})
|
||||
else:
|
||||
TABLE_DIRECT.update({
|
||||
'except_cond3': ( '%|except %c, %c:\n', 1, 6 ),
|
||||
})
|
||||
|
||||
|
||||
##########################
|
||||
# Python 3.2 and 3.3 only
|
||||
##########################
|
||||
|
Reference in New Issue
Block a user