You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-02 16:44:46 +08:00
38 lines
1.0 KiB
Python
38 lines
1.0 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:
|
|
rv = rv + '\n' + str(k).replace('\n', '\n ')
|
|
return rv
|