You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,6 +1,7 @@
|
|||||||
*.pyc
|
*.pyc
|
||||||
*_dis
|
*_dis
|
||||||
*~
|
*~
|
||||||
|
*.pyc
|
||||||
/.cache
|
/.cache
|
||||||
/.eggs
|
/.eggs
|
||||||
/.python-version
|
/.python-version
|
||||||
|
@@ -1,6 +1,7 @@
|
|||||||
import sys
|
import sys
|
||||||
from uncompyle6 import PYTHON3
|
from uncompyle6 import PYTHON3
|
||||||
from uncompyle6.scanners.tok import NoneToken
|
from uncompyle6.scanners.tok import NoneToken
|
||||||
|
from spark_parser.ast import AST as spark_AST
|
||||||
|
|
||||||
if PYTHON3:
|
if PYTHON3:
|
||||||
intern = sys.intern
|
intern = sys.intern
|
||||||
@@ -9,30 +10,42 @@ else:
|
|||||||
from UserList import UserList
|
from UserList import UserList
|
||||||
|
|
||||||
|
|
||||||
class AST(UserList):
|
class AST(spark_AST):
|
||||||
def __init__(self, kind, kids=[]):
|
|
||||||
self.type = intern(kind)
|
|
||||||
UserList.__init__(self, kids)
|
|
||||||
|
|
||||||
def isNone(self):
|
def isNone(self):
|
||||||
"""An AST None token. We can't use regular list comparisons
|
"""An AST None token. We can't use regular list comparisons
|
||||||
because AST token offsets might be different"""
|
because AST token offsets might be different"""
|
||||||
return len(self.data) == 1 and NoneToken == self.data[0]
|
return len(self.data) == 1 and NoneToken == self.data[0]
|
||||||
|
|
||||||
def __getslice__(self, low, high): return self.data[low:high]
|
def __repr__(self):
|
||||||
|
return self.__repr1__('', None)
|
||||||
|
|
||||||
def __eq__(self, o):
|
def __repr1__(self, indent, sibNum=None):
|
||||||
if isinstance(o, AST):
|
|
||||||
return self.type == o.type \
|
|
||||||
and UserList.__eq__(self, o)
|
|
||||||
else:
|
|
||||||
return self.type == o
|
|
||||||
|
|
||||||
def __hash__(self):
|
|
||||||
return hash(self.type)
|
|
||||||
|
|
||||||
def __repr__(self, indent=''):
|
|
||||||
rv = str(self.type)
|
rv = str(self.type)
|
||||||
for k in self:
|
if sibNum is not None:
|
||||||
rv = rv + '\n' + str(k).replace('\n', '\n ')
|
rv = "%2d. %s" % (sibNum, rv)
|
||||||
|
enumerate_children = False
|
||||||
|
if len(self) > 1:
|
||||||
|
rv += " (%d)" % (len(self))
|
||||||
|
enumerate_children = True
|
||||||
|
rv = indent + rv
|
||||||
|
indent += ' '
|
||||||
|
i = 0
|
||||||
|
for node in self:
|
||||||
|
if hasattr(node, '__repr1__'):
|
||||||
|
if enumerate_children:
|
||||||
|
child = node.__repr1__(indent, i)
|
||||||
|
else:
|
||||||
|
child = node.__repr1__(indent, None)
|
||||||
|
else:
|
||||||
|
inst = str(node)
|
||||||
|
if inst.startswith("\n"):
|
||||||
|
# Nuke leading \n
|
||||||
|
inst = inst[1:]
|
||||||
|
if enumerate_children:
|
||||||
|
child = indent + "%2d. %s" % (i, inst)
|
||||||
|
else:
|
||||||
|
child = indent + inst
|
||||||
|
pass
|
||||||
|
rv += "\n" + child
|
||||||
|
i += 1
|
||||||
return rv
|
return rv
|
||||||
|
@@ -43,11 +43,11 @@ class Token:
|
|||||||
pattr = self.pattr if self.pattr is not None else ''
|
pattr = self.pattr if self.pattr is not None else ''
|
||||||
prefix = '\n%4d ' % self.linestart if self.linestart else (' ' * 6)
|
prefix = '\n%4d ' % self.linestart if self.linestart else (' ' * 6)
|
||||||
return (prefix +
|
return (prefix +
|
||||||
('%6s\t%-17s %r' % (self.offset, self.type, pattr)))
|
('%6s %-17s %r' % (self.offset, self.type, pattr)))
|
||||||
|
|
||||||
def format(self):
|
def format(self):
|
||||||
prefix = '\n%4d ' % self.linestart if self.linestart else (' ' * 5)
|
prefix = '\n%4d ' % self.linestart if self.linestart else (' ' * 6)
|
||||||
offset_opname = '%6s\t%-17s' % (self.offset, self.type)
|
offset_opname = '%6s %-17s' % (self.offset, self.type)
|
||||||
argstr = "%6d " % self.attr if isinstance(self.attr, int) else (' '*7)
|
argstr = "%6d " % self.attr if isinstance(self.attr, int) else (' '*7)
|
||||||
pattr = self.pattr if self.pattr is not None else ''
|
pattr = self.pattr if self.pattr is not None else ''
|
||||||
return "%s%s%s %r" % (prefix, offset_opname, argstr, pattr)
|
return "%s%s%s %r" % (prefix, offset_opname, argstr, pattr)
|
||||||
|
Reference in New Issue
Block a user