You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
python3 compatibiity and remove some flake8 warnings.
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import uncompyle6
|
import uncompyle6
|
||||||
from uncompyle6 import uncompyle, walker, verify, magics
|
from uncompyle6 import uncompyle, walker, verify, magics
|
||||||
from uncompyle6.spark import GenericASTTraversal, GenericASTTraversalPruningException
|
from uncompyle6.spark import GenericASTTraversal, GenericASTTraversalPruningException
|
||||||
@@ -28,7 +30,6 @@ class FindWalker(walker.Walker, object):
|
|||||||
self.found_offset = False
|
self.found_offset = False
|
||||||
self.offsets = {}
|
self.offsets = {}
|
||||||
|
|
||||||
|
|
||||||
f = property(lambda s: s.__params['f'],
|
f = property(lambda s: s.__params['f'],
|
||||||
lambda s, x: s.__params.__setitem__('f', x),
|
lambda s, x: s.__params.__setitem__('f', x),
|
||||||
lambda s: s.__params.__delitem__('f'),
|
lambda s: s.__params.__delitem__('f'),
|
||||||
@@ -85,7 +86,6 @@ class FindWalker(walker.Walker, object):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
def find_source(self, offset, ast, customize, isLambda=0, returnNone=False):
|
def find_source(self, offset, ast, customize, isLambda=0, returnNone=False):
|
||||||
"""convert AST to source code"""
|
"""convert AST to source code"""
|
||||||
|
|
||||||
@@ -133,7 +133,7 @@ class FindWalker(walker.Walker, object):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def uncompyle_find(version, co, find_offset, out=sys.stdout, showasm=0, showast=0):
|
def uncompyle_find(version, co, find_offset, out=sys.stdout, showasm=0, showast=0):
|
||||||
assert type(co) == types.CodeType
|
assert isinstance(co, types.CodeType)
|
||||||
# store final output stream for case of error
|
# store final output stream for case of error
|
||||||
__real_out = out or sys.stdout
|
__real_out = out or sys.stdout
|
||||||
if version == 2.7:
|
if version == 2.7:
|
||||||
@@ -154,8 +154,8 @@ def uncompyle_find(version, co, find_offset, out=sys.stdout, showasm=0, showast=
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
ast = walk.build_ast(tokens, customize)
|
ast = walk.build_ast(tokens, customize)
|
||||||
except walker.ParserError, e : # parser failed, dump disassembly
|
except walker.ParserError as e : # parser failed, dump disassembly
|
||||||
print >>__real_out, e
|
print(e, file=__real_out)
|
||||||
raise
|
raise
|
||||||
del tokens # save memory
|
del tokens # save memory
|
||||||
|
|
||||||
@@ -187,8 +187,8 @@ def uncompyle_test():
|
|||||||
try:
|
try:
|
||||||
co = frame.f_code
|
co = frame.f_code
|
||||||
uncompyle(2.7, co, sys.stdout, 1)
|
uncompyle(2.7, co, sys.stdout, 1)
|
||||||
print
|
print()
|
||||||
print '------------------------'
|
print('------------------------')
|
||||||
uncompyle_find(2.7, co, 33)
|
uncompyle_find(2.7, co, 33)
|
||||||
finally:
|
finally:
|
||||||
del frame
|
del frame
|
||||||
|
@@ -31,8 +31,14 @@ from __future__ import print_function
|
|||||||
'''
|
'''
|
||||||
|
|
||||||
import sys, types, os
|
import sys, types, os
|
||||||
|
|
||||||
|
if (sys.version_info > (3, 0)):
|
||||||
|
from . import walker, verify, magics
|
||||||
|
from . import disas as dis
|
||||||
|
else:
|
||||||
import walker, verify, magics
|
import walker, verify, magics
|
||||||
import disas as dis
|
import disas as dis
|
||||||
|
|
||||||
import marshal
|
import marshal
|
||||||
|
|
||||||
sys.setrecursionlimit(5000)
|
sys.setrecursionlimit(5000)
|
||||||
@@ -90,7 +96,8 @@ def uncompyle(version, co, out=None, showasm=0, showast=0):
|
|||||||
# store final output stream for case of error
|
# store final output stream for case of error
|
||||||
__real_out = out or sys.stdout
|
__real_out = out or sys.stdout
|
||||||
if co.co_filename:
|
if co.co_filename:
|
||||||
print >>__real_out, '# Embedded file name: %s' % co.co_filename
|
print('# Embedded file name: %s' % co.co_filename,
|
||||||
|
file=__real_out)
|
||||||
# diff scanner
|
# diff scanner
|
||||||
if version == 2.7:
|
if version == 2.7:
|
||||||
import scanner27 as scan
|
import scanner27 as scan
|
||||||
@@ -109,7 +116,7 @@ def uncompyle(version, co, out=None, showasm=0, showast=0):
|
|||||||
try:
|
try:
|
||||||
ast = walk.build_ast(tokens, customize)
|
ast = walk.build_ast(tokens, customize)
|
||||||
except walker.ParserError as e : # parser failed, dump disassembly
|
except walker.ParserError as e : # parser failed, dump disassembly
|
||||||
print >>__real_out, e
|
print(e, file=__real_out)
|
||||||
raise
|
raise
|
||||||
del tokens # save memory
|
del tokens # save memory
|
||||||
|
|
||||||
@@ -190,7 +197,7 @@ def main(in_base, out_base, files, codes, outfile=None,
|
|||||||
|
|
||||||
for file in files:
|
for file in files:
|
||||||
infile = os.path.join(in_base, file)
|
infile = os.path.join(in_base, file)
|
||||||
# print >>sys.stderr, infile
|
# print (infile, file=sys.stderr)
|
||||||
|
|
||||||
if of: # outfile was given as parameter
|
if of: # outfile was given as parameter
|
||||||
outstream = _get_outstream(outfile)
|
outstream = _get_outstream(outfile)
|
||||||
@@ -199,7 +206,7 @@ def main(in_base, out_base, files, codes, outfile=None,
|
|||||||
else:
|
else:
|
||||||
outfile = os.path.join(out_base, file) + '_dis'
|
outfile = os.path.join(out_base, file) + '_dis'
|
||||||
outstream = _get_outstream(outfile)
|
outstream = _get_outstream(outfile)
|
||||||
# print >>sys.stderr, outfile
|
# print(outfile, file=sys.stderr)
|
||||||
|
|
||||||
# try to decomyple the input file
|
# try to decomyple the input file
|
||||||
try:
|
try:
|
||||||
@@ -232,8 +239,8 @@ def main(in_base, out_base, files, codes, outfile=None,
|
|||||||
verify_failed_files += 1
|
verify_failed_files += 1
|
||||||
os.rename(outfile, outfile + '_unverified')
|
os.rename(outfile, outfile + '_unverified')
|
||||||
if not outfile:
|
if not outfile:
|
||||||
print >>sys.stderr, "### Error Verifiying", file
|
print("### Error Verifiying %s" % file, file=sys.stderr)
|
||||||
print >>sys.stderr, e
|
print(e, file=sys.stderr)
|
||||||
else:
|
else:
|
||||||
okay_files += 1
|
okay_files += 1
|
||||||
if not outfile: print('\n# okay decompyling', infile, __memUsage())
|
if not outfile: print('\n# okay decompyling', infile, __memUsage())
|
||||||
|
@@ -1,3 +1,5 @@
|
|||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
'''
|
'''
|
||||||
Copyright (c) 1999 John Aycock
|
Copyright (c) 1999 John Aycock
|
||||||
Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||||
@@ -41,9 +43,13 @@
|
|||||||
makes the engine walk down to N[C] before evaluating the escape code.
|
makes the engine walk down to N[C] before evaluating the escape code.
|
||||||
'''
|
'''
|
||||||
|
|
||||||
import sys, re, cStringIO
|
try:
|
||||||
from types import ListType, TupleType, DictType, \
|
from StringIO import StringIO
|
||||||
EllipsisType, IntType, CodeType
|
except ImportError:
|
||||||
|
from io import StringIO
|
||||||
|
|
||||||
|
import sys, re
|
||||||
|
from types import IntType, CodeType
|
||||||
|
|
||||||
from spark import GenericASTTraversal
|
from spark import GenericASTTraversal
|
||||||
import parser
|
import parser
|
||||||
@@ -488,7 +494,7 @@ class Walker(GenericASTTraversal, object):
|
|||||||
self.pending_newlines = 0
|
self.pending_newlines = 0
|
||||||
self.__params = {
|
self.__params = {
|
||||||
'_globals': {},
|
'_globals': {},
|
||||||
'f': cStringIO.StringIO(),
|
'f': StringIO(),
|
||||||
'indent': indent,
|
'indent': indent,
|
||||||
'isLambda': isLambda,
|
'isLambda': isLambda,
|
||||||
}
|
}
|
||||||
@@ -704,7 +710,7 @@ class Walker(GenericASTTraversal, object):
|
|||||||
# change:hG/2002-02-07: this was done for all negative integers
|
# change:hG/2002-02-07: this was done for all negative integers
|
||||||
# todo: check whether this is necessary in Python 2.1
|
# todo: check whether this is necessary in Python 2.1
|
||||||
self.write( hex(data) )
|
self.write( hex(data) )
|
||||||
elif datatype is EllipsisType:
|
elif datatype is type(Ellipsis):
|
||||||
self.write('...')
|
self.write('...')
|
||||||
elif data is None:
|
elif data is None:
|
||||||
# LOAD_CONST 'None' only occurs, when None is
|
# LOAD_CONST 'None' only occurs, when None is
|
||||||
@@ -1118,7 +1124,7 @@ class Walker(GenericASTTraversal, object):
|
|||||||
if m.group('child'):
|
if m.group('child'):
|
||||||
node = node[int(m.group('child'))]
|
node = node[int(m.group('child'))]
|
||||||
except:
|
except:
|
||||||
print node.__dict__
|
print(node.__dict__)
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if typ == '%': self.write('%')
|
if typ == '%': self.write('%')
|
||||||
@@ -1166,7 +1172,7 @@ class Walker(GenericASTTraversal, object):
|
|||||||
try:
|
try:
|
||||||
self.write(eval(expr, d, d))
|
self.write(eval(expr, d, d))
|
||||||
except:
|
except:
|
||||||
print node
|
print(node)
|
||||||
raise
|
raise
|
||||||
m = escape.search(fmt, i)
|
m = escape.search(fmt, i)
|
||||||
self.write(fmt[i:])
|
self.write(fmt[i:])
|
||||||
@@ -1268,9 +1274,9 @@ class Walker(GenericASTTraversal, object):
|
|||||||
|
|
||||||
if default:
|
if default:
|
||||||
if self.showast:
|
if self.showast:
|
||||||
print '--', name
|
print('--', name)
|
||||||
print default
|
print(default)
|
||||||
print '--'
|
print('--')
|
||||||
result = '%s = %s' % (name, self.traverse(default, indent='') )
|
result = '%s = %s' % (name, self.traverse(default, indent='') )
|
||||||
if result[-2:] == '= ': # default was 'LOAD_CONST None'
|
if result[-2:] == '= ': # default was 'LOAD_CONST None'
|
||||||
result += 'None'
|
result += 'None'
|
||||||
@@ -1408,14 +1414,14 @@ class Walker(GenericASTTraversal, object):
|
|||||||
self.return_none = rn
|
self.return_none = rn
|
||||||
|
|
||||||
def build_ast(self, tokens, customize, isLambda=0, noneInNames=False):
|
def build_ast(self, tokens, customize, isLambda=0, noneInNames=False):
|
||||||
assert type(tokens) == ListType
|
|
||||||
# assert isinstance(tokens[0], Token)
|
# assert isinstance(tokens[0], Token)
|
||||||
|
|
||||||
if isLambda:
|
if isLambda:
|
||||||
tokens.append(Token('LAMBDA_MARKER'))
|
tokens.append(Token('LAMBDA_MARKER'))
|
||||||
try:
|
try:
|
||||||
ast = parser.parse(tokens, customize)
|
ast = parser.parse(tokens, customize)
|
||||||
except parser.ParserError, e:
|
except parser.ParserError as e:
|
||||||
raise ParserError(e, tokens)
|
raise ParserError(e, tokens)
|
||||||
if self.showast:
|
if self.showast:
|
||||||
self.print_(repr(ast))
|
self.print_(repr(ast))
|
||||||
@@ -1433,7 +1439,7 @@ class Walker(GenericASTTraversal, object):
|
|||||||
# Build AST from disassembly.
|
# Build AST from disassembly.
|
||||||
try:
|
try:
|
||||||
ast = parser.parse(tokens, customize)
|
ast = parser.parse(tokens, customize)
|
||||||
except parser.ParserError, e:
|
except parser.ParserError as e:
|
||||||
raise ParserError(e, tokens)
|
raise ParserError(e, tokens)
|
||||||
|
|
||||||
if self.showast:
|
if self.showast:
|
||||||
|
Reference in New Issue
Block a user