You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
separate semantic action version differences
Added customize_for_version which uses is_pypy and version to adjust tables
This commit is contained in:
@@ -330,37 +330,6 @@ TABLE_DIRECT = {
|
||||
'kv2': ( '%c: %c', 1, 2 ),
|
||||
'mapexpr': ( '{%[1]C}', (0, maxint, ', ') ),
|
||||
|
||||
#######################
|
||||
# Python 2.3 Additions
|
||||
#######################
|
||||
|
||||
# Import style for 2.0-2.3
|
||||
'importstmt20': ( '%|import %c\n', 1),
|
||||
'importstar20': ( '%|from %[1]{pattr} import *\n', ),
|
||||
'importfrom20': ( '%|from %[1]{pattr} import %c\n', 2 ),
|
||||
'importlist20': ( '%C', (0, maxint, ', ') ),
|
||||
|
||||
#######################
|
||||
# Python 2.5 Additions
|
||||
#######################
|
||||
|
||||
# Import style for 2.5+
|
||||
'importstmt': ( '%|import %c\n', 2),
|
||||
'importstar': ( '%|from %[2]{pattr} import *\n', ),
|
||||
'importfrom': ( '%|from %[2]{pattr} import %c\n', 3 ),
|
||||
'importmultiple': ( '%|import %c%c\n', 2, 3 ),
|
||||
'import_cont' : ( ', %c', 2 ),
|
||||
|
||||
########################
|
||||
# Python 3.2 and 3.3 only
|
||||
#######################
|
||||
'store_locals': ( '%|# inspect.currentframe().f_locals = __locals__\n', ),
|
||||
|
||||
########################
|
||||
# Python 3.4+ Additions
|
||||
#######################
|
||||
'LOAD_CLASSDEREF': ( '%{pattr}', ),
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -537,26 +506,11 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.version = version
|
||||
self.is_pypy = is_pypy
|
||||
|
||||
if 2.0 <= version <= 2.3:
|
||||
TABLE_DIRECT['tryfinallystmt'] = (
|
||||
'%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 4 )
|
||||
if version < 3.0:
|
||||
TABLE_R.update({
|
||||
'STORE_SLICE+0': ( '%c[:]', 0 ),
|
||||
'STORE_SLICE+1': ( '%c[%p:]', 0, (1, 100) ),
|
||||
'STORE_SLICE+2': ( '%c[:%p]', 0, (1, 100) ),
|
||||
'STORE_SLICE+3': ( '%c[%p:%p]', 0, (1, 100), (2, 100) ),
|
||||
'DELETE_SLICE+0': ( '%|del %c[:]\n', 0 ),
|
||||
'DELETE_SLICE+1': ( '%|del %c[%c:]\n', 0, 1 ),
|
||||
'DELETE_SLICE+2': ( '%|del %c[:%c]\n', 0, 1 ),
|
||||
'DELETE_SLICE+3': ( '%|del %c[%c:%c]\n', 0, 1, 2 ),
|
||||
})
|
||||
|
||||
self.customize_pypy(is_pypy)
|
||||
self.customize_for_version(is_pypy, version)
|
||||
return
|
||||
|
||||
@staticmethod
|
||||
def customize_pypy(is_pypy):
|
||||
def customize_for_version(is_pypy, version):
|
||||
if is_pypy:
|
||||
########################
|
||||
# PyPy changes
|
||||
@@ -581,7 +535,58 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
'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:
|
||||
TABLE_R.update({
|
||||
'STORE_SLICE+0': ( '%c[:]', 0 ),
|
||||
'STORE_SLICE+1': ( '%c[%p:]', 0, (1, 100) ),
|
||||
'STORE_SLICE+2': ( '%c[:%p]', 0, (1, 100) ),
|
||||
'STORE_SLICE+3': ( '%c[%p:%p]', 0, (1, 100), (2, 100) ),
|
||||
'DELETE_SLICE+0': ( '%|del %c[:]\n', 0 ),
|
||||
'DELETE_SLICE+1': ( '%|del %c[%c:]\n', 0, 1 ),
|
||||
'DELETE_SLICE+2': ( '%|del %c[:%c]\n', 0, 1 ),
|
||||
'DELETE_SLICE+3': ( '%|del %c[%c:%c]\n', 0, 1, 2 ),
|
||||
})
|
||||
|
||||
if 2.0 <= version <= 2.3:
|
||||
TABLE_DIRECT.update({
|
||||
'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 4 )
|
||||
})
|
||||
###########################
|
||||
# Import style for 2.0-2.3
|
||||
###########################
|
||||
TABLE_DIRECT.update({
|
||||
'importstmt20': ( '%|import %c\n', 1),
|
||||
'importstar20': ( '%|from %[1]{pattr} import *\n', ),
|
||||
'importfrom20': ( '%|from %[1]{pattr} import %c\n', 2 ),
|
||||
'importlist20': ( '%C', (0, maxint, ', ') ),
|
||||
})
|
||||
elif version >= 2.5:
|
||||
########################
|
||||
# Import style for 2.5+
|
||||
########################
|
||||
TABLE_DIRECT.update({
|
||||
'importstmt': ( '%|import %c\n', 2),
|
||||
'importstar': ( '%|from %[2]{pattr} import *\n', ),
|
||||
'importfrom': ( '%|from %[2]{pattr} import %c\n', 3 ),
|
||||
'importmultiple': ( '%|import %c%c\n', 2, 3 ),
|
||||
'import_cont' : ( ', %c', 2 ),
|
||||
})
|
||||
|
||||
##########################
|
||||
# Python 3.2 and 3.3 only
|
||||
##########################
|
||||
if 3.2 <= version <= 3.3:
|
||||
TABLE_DIRECT.update({
|
||||
'store_locals': ( '%|# inspect.currentframe().f_locals = __locals__\n', ),
|
||||
})
|
||||
elif version >= 3.4:
|
||||
########################
|
||||
# Python 3.4+ Additions
|
||||
#######################
|
||||
TABLE_DIRECT.update({
|
||||
'LOAD_CLASSDEREF': ( '%{pattr}', ),
|
||||
})
|
||||
return
|
||||
|
||||
f = property(lambda s: s.params['f'],
|
||||
lambda s, x: s.params.__setitem__('f', x),
|
||||
@@ -1025,7 +1030,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.write(func_name)
|
||||
|
||||
self.indentMore()
|
||||
self.make_function(node, isLambda=False, code=code)
|
||||
self.make_function(node, isLambda=False, codeNode=code)
|
||||
|
||||
if len(self.param_stack) > 1:
|
||||
self.write('\n\n')
|
||||
@@ -1035,7 +1040,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.prune() # stop recursing
|
||||
|
||||
def n_mklambda(self, node):
|
||||
self.make_function(node, isLambda=True, code=node[-2])
|
||||
self.make_function(node, isLambda=True, codeNode=node[-2])
|
||||
self.prune() # stop recursing
|
||||
|
||||
def n_list_compr(self, node):
|
||||
@@ -1906,7 +1911,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
# return self.traverse(node[1])
|
||||
raise Exception("Can't find tuple parameter " + name)
|
||||
|
||||
def make_function(self, node, isLambda, nested=1, code=None):
|
||||
def make_function(self, node, isLambda, nested=1, codeNode=None):
|
||||
"""Dump function defintion, doc string, and function body."""
|
||||
|
||||
def build_param(ast, name, default):
|
||||
@@ -1947,12 +1952,12 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
pos_args, kw_args, annotate_args = args_node.attr
|
||||
else:
|
||||
defparams = node[:args_node.attr]
|
||||
kw_args, annotate_args = (0, 0)
|
||||
kw_args = 0
|
||||
pass
|
||||
|
||||
if 3.0 <= self.version <= 3.2:
|
||||
lambda_index = -2
|
||||
elif 3.03<= self.version:
|
||||
elif 3.03 <= self.version:
|
||||
lambda_index = -3
|
||||
else:
|
||||
lambda_index = None
|
||||
@@ -1961,7 +1966,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
assert node[lambda_index].type == 'LOAD_LAMBDA'
|
||||
code = node[lambda_index].attr
|
||||
else:
|
||||
code = code.attr
|
||||
code = codeNode.attr
|
||||
|
||||
assert iscode(code)
|
||||
code = Code(code, self.scanner, self.currentclass)
|
||||
|
Reference in New Issue
Block a user