You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Simpify python 2.1 grammar Fix bug with -t ...
Wasn't showing source text when -t option was given
This commit is contained in:
@@ -144,7 +144,7 @@ def main_bin():
|
||||
usage()
|
||||
|
||||
if outfile == '-':
|
||||
if 'do_verify' in options and len(files) == 1:
|
||||
if 'do_verify' in options and options['do_verify'] and len(files) == 1:
|
||||
junk, outfile = tempfile.mkstemp(suffix=".pyc",
|
||||
prefix=files[0][0:-4]+'-')
|
||||
else:
|
||||
|
@@ -13,35 +13,18 @@ class Python21Parser(Python22Parser):
|
||||
|
||||
def p_forstmt21(self, args):
|
||||
"""
|
||||
_for ::= LOAD_CONST FOR_LOOP
|
||||
forstmt ::= SETUP_LOOP expr _for designator
|
||||
return_stmts
|
||||
POP_BLOCK COME_FROM
|
||||
forstmt ::= SETUP_LOOP expr _for designator
|
||||
l_stmts_opt _jump_back
|
||||
POP_BLOCK COME_FROM
|
||||
_for ::= LOAD_CONST FOR_LOOP
|
||||
forstmt ::= SETUP_LOOP expr _for designator
|
||||
return_stmts
|
||||
POP_BLOCK COME_FROM
|
||||
forstmt ::= SETUP_LOOP expr _for designator
|
||||
l_stmts_opt _jump_back
|
||||
POP_BLOCK COME_FROM
|
||||
"""
|
||||
|
||||
def p_import21(self, args):
|
||||
'''
|
||||
# These are be relevant for only Python 2.0 and 2.1
|
||||
stmt ::= importstmt2
|
||||
stmt ::= importfrom2
|
||||
stmt ::= importstar
|
||||
stmt ::= import_as_cont
|
||||
stmt ::= import_as
|
||||
importfrom2 ::= LOAD_CONST IMPORT_NAME importlist2 POP_TOP
|
||||
importlist2 ::= importlist2 import_as
|
||||
importstmt2 ::= LOAD_CONST IMPORT_NAME designator
|
||||
importstmt2 ::= LOAD_CONST IMPORT_NAME IMPORT_FROM designator POP_TOP
|
||||
importstar ::= LOAD_CONST LOAD_CONST IMPORT_NAME_CONT IMPORT_STAR
|
||||
importfrom ::= LOAD_CONST LOAD_CONST IMPORT_NAME_CONT importlist2 POP_TOP
|
||||
import_as ::= LOAD_CONST IMPORT_NAME LOAD_ATTR designator
|
||||
import_as ::= LOAD_CONST IMPORT_NAME LOAD_ATTR LOAD_ATTR designator
|
||||
import_as ::= LOAD_CONST IMPORT_NAME LOAD_ATTR LOAD_ATTR LOAD_ATTR designator
|
||||
import_as ::= IMPORT_FROM designator
|
||||
import_as_cont ::= LOAD_CONST IMPORT_NAME_CONT designator
|
||||
import_as_cont ::= IMPORT_NAME_CONT load_attrs designator
|
||||
import_as ::= IMPORT_NAME_CONT designator
|
||||
'''
|
||||
|
||||
class Python21ParserSingle(Python22Parser, PythonParserSingle):
|
||||
|
@@ -564,19 +564,6 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
TABLE_DIRECT.update({
|
||||
'tryfinallystmt': ( '%|try:\n%+%c%-%|finally:\n%+%c%-\n\n', 1, 4 )
|
||||
})
|
||||
if version == 2.1:
|
||||
###########################
|
||||
# Import style for 2.0-2.3
|
||||
###########################
|
||||
TABLE_DIRECT.update({
|
||||
'importstmt2': ( '%|import %c\n', 1),
|
||||
'import_as_cont': ( '%|import %c as %c\n', 1, 2),
|
||||
'importstar2': ( '%|from %[1]{pattr} import *\n', ),
|
||||
'importfrom2': ( '%|from %[1]{pattr} import %c\n', 2 ),
|
||||
'importlist2': ( '%C', (0, maxint, ', ') ),
|
||||
'IMPORT_NAME': ( '%{pattr}', ),
|
||||
'IMPORT_NAME_CONT': ( '%{pattr}', ),
|
||||
})
|
||||
|
||||
elif version >= 2.5:
|
||||
########################
|
||||
@@ -1059,17 +1046,14 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.prune()
|
||||
|
||||
def n_import_as(self, node):
|
||||
if self.version == 2.1 and node == 'import_as_cont':
|
||||
self.write("\n", self.indent, "import ")
|
||||
iname = node[1].pattr if node[0] == 'LOAD_CONST' else node[0].pattr
|
||||
assert node[-1][-1].type.startswith('STORE_')
|
||||
sname = node[-1][-1].pattr # assume one of STORE_.... here
|
||||
store_node = node[-1][-1]
|
||||
assert store_node.type.startswith('STORE_')
|
||||
iname = node[0].pattr # import name
|
||||
sname = store_node.pattr # store_name
|
||||
if iname and iname == sname or iname.startswith(sname + '.'):
|
||||
self.write(iname)
|
||||
else:
|
||||
self.write(iname, ' as ', sname)
|
||||
if self.version == 2.1 and node == 'import_as_cont':
|
||||
self.write("\n")
|
||||
self.prune() # stop recursing
|
||||
|
||||
n_import_as_cont = n_import_as
|
||||
|
Reference in New Issue
Block a user