You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
43 lines
1.2 KiB
Python
43 lines
1.2 KiB
Python
import sys
|
|
from uncompyle6 import PYTHON3
|
|
from uncompyle6.scanners.tok import NoneToken
|
|
|
|
if PYTHON3:
|
|
intern = sys.intern
|
|
from collections import UserList
|
|
else:
|
|
from UserList import UserList
|
|
|
|
|
|
class AST(UserList):
|
|
def __init__(self, kind, kids=[]):
|
|
self.type = intern(kind)
|
|
UserList.__init__(self, kids)
|
|
|
|
def isNone(self):
|
|
"""An AST None token. We can't use regular list comparisons
|
|
because AST token offsets might be different"""
|
|
return len(self.data) == 1 and NoneToken == self.data[0]
|
|
|
|
def __getslice__(self, low, high): return self.data[low:high]
|
|
|
|
def __eq__(self, o):
|
|
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)
|
|
for k in self:
|
|
child_text = str(k).replace('\n', '\n ')
|
|
if hasattr(k, '__len__'):
|
|
rv += '\n(%d) %s' % (len(k), child_text)
|
|
else:
|
|
rv += '\n' + child_text
|
|
return rv
|