You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Usuability fixes
* try using format for __str__ * Explicitly nuke self.attr and self.pattr when no arg * Sync pysource and format wrt make_function
This commit is contained in:
@@ -29,6 +29,9 @@ class Token:
|
||||
self.pattr = pattr
|
||||
self.offset = offset
|
||||
self.linestart = linestart
|
||||
if has_arg == False:
|
||||
self.attr = None
|
||||
self.pattr = None
|
||||
self.opc = opc
|
||||
|
||||
def __eq__(self, o):
|
||||
@@ -43,11 +46,11 @@ class Token:
|
||||
def __repr__(self):
|
||||
return str(self.type)
|
||||
|
||||
def __str__(self):
|
||||
pattr = self.pattr if self.pattr is not None else ''
|
||||
prefix = '\n%3d ' % self.linestart if self.linestart else (' ' * 6)
|
||||
return (prefix +
|
||||
('%9s %-18s %r' % (self.offset, self.type, pattr)))
|
||||
# def __str__(self):
|
||||
# pattr = self.pattr if self.pattr is not None else ''
|
||||
# prefix = '\n%3d ' % self.linestart if self.linestart else (' ' * 6)
|
||||
# return (prefix +
|
||||
# ('%9s %-18s %r' % (self.offset, self.type, pattr)))
|
||||
|
||||
def format(self):
|
||||
prefix = '\n%4d ' % self.linestart if self.linestart else (' ' * 6)
|
||||
@@ -73,6 +76,8 @@ class Token:
|
||||
pattr = ''
|
||||
return "%s%s%s %r" % (prefix, offset_opname, argstr, pattr)
|
||||
|
||||
__str__ = format
|
||||
|
||||
def __hash__(self):
|
||||
return hash(self.type)
|
||||
|
||||
|
@@ -339,7 +339,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
self.preorder(node[0])
|
||||
finish = len(self.f.getvalue())
|
||||
if hasattr(node[0], 'offset'):
|
||||
self.set_pos_info(node[0], self.last_finish, )
|
||||
self.set_pos_info(node[0], start, len(self.f.getvalue()))
|
||||
self.write(')')
|
||||
self.last_finish = finish + 1
|
||||
else:
|
||||
@@ -534,7 +534,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
self.write(func_name)
|
||||
|
||||
self.indentMore()
|
||||
self.make_function(node, isLambda=False, code_index=code_index)
|
||||
self.make_function(node, isLambda=False, code=code)
|
||||
|
||||
self.set_pos_info(node, start, len(self.f.getvalue()))
|
||||
|
||||
@@ -1613,7 +1613,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
self.set_pos_info(last_node, startnode_start, self.last_finish)
|
||||
return
|
||||
|
||||
def make_function(self, node, isLambda, nested=1, code_index=-2):
|
||||
def make_function(self, node, isLambda, nested=1, code=None):
|
||||
"""Dump function defintion, doc string, and function body."""
|
||||
|
||||
def build_param(ast, name, default):
|
||||
@@ -1664,7 +1664,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
if self.version > 3.0 and isLambda and iscode(node[-3].attr):
|
||||
code = node[-3].attr
|
||||
else:
|
||||
code = node[code_index].attr
|
||||
code = code.attr
|
||||
|
||||
assert iscode(code)
|
||||
code = Code(code, self.scanner, self.currentclass)
|
||||
|
@@ -132,7 +132,7 @@ class CmpErrorMember(VerifyCmpError):
|
||||
# these members are ignored
|
||||
__IGNORE_CODE_MEMBERS__ = ['co_filename', 'co_firstlineno', 'co_lnotab', 'co_stacksize', 'co_names']
|
||||
|
||||
def cmp_code_objects(version, code_obj1, code_obj2, name=''):
|
||||
def cmp_code_objects(version, code_obj1, code_obj2, name='', is_pypy=False):
|
||||
"""
|
||||
Compare two code-objects.
|
||||
|
||||
@@ -193,9 +193,17 @@ def cmp_code_objects(version, code_obj1, code_obj2, name=''):
|
||||
import uncompyle6.scanners.scanner26 as scan
|
||||
scanner = scan.Scanner26()
|
||||
elif version == 2.7:
|
||||
if is_pypy:
|
||||
import uncompyle6.scanners.pypy27 as scan
|
||||
scanner = scan.ScannerPyPy27()
|
||||
else:
|
||||
import uncompyle6.scanners.scanner27 as scan
|
||||
scanner = scan.Scanner27()
|
||||
elif version == 3.2:
|
||||
if is_pypy:
|
||||
import uncompyle6.scanners.pypy32 as scan
|
||||
scanner = scan.ScannerPyPy32()
|
||||
else:
|
||||
import uncompyle6.scanners.scanner32 as scan
|
||||
scanner = scan.Scanner32()
|
||||
elif version == 3.3:
|
||||
@@ -333,13 +341,8 @@ def cmp_code_objects(version, code_obj1, code_obj2, name=''):
|
||||
|
||||
class Token(scanner.Token):
|
||||
"""Token class with changed semantics for 'cmp()'."""
|
||||
|
||||
def __cmp__(self, o):
|
||||
t = self.type # shortcut
|
||||
loads = ('LOAD_NAME', 'LOAD_GLOBAL', 'LOAD_CONST')
|
||||
if t in loads and o.type in loads:
|
||||
if self.pattr == 'None' and o.pattr is None:
|
||||
return 0
|
||||
if t == 'BUILD_TUPLE_0' and o.type == 'LOAD_CONST' and o.pattr == ():
|
||||
return 0
|
||||
if t == 'COME_FROM' == o.type:
|
||||
|
Reference in New Issue
Block a user