UserList.py (3827B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\carbon\common\stdlib\UserList.py 2 import collections 3 4 class UserList(collections.MutableSequence): 5 6 def __init__(self, initlist = None): 7 self.data = [] 8 if initlist is not None: 9 if type(initlist) == type(self.data): 10 self.data[:] = initlist 11 elif isinstance(initlist, UserList): 12 self.data[:] = initlist.data[:] 13 else: 14 self.data = list(initlist) 15 16 def __repr__(self): 17 return repr(self.data) 18 19 def __lt__(self, other): 20 return self.data < self.__cast(other) 21 22 def __le__(self, other): 23 return self.data <= self.__cast(other) 24 25 def __eq__(self, other): 26 return self.data == self.__cast(other) 27 28 def __ne__(self, other): 29 return self.data != self.__cast(other) 30 31 def __gt__(self, other): 32 return self.data > self.__cast(other) 33 34 def __ge__(self, other): 35 return self.data >= self.__cast(other) 36 37 def __cast(self, other): 38 if isinstance(other, UserList): 39 return other.data 40 else: 41 return other 42 43 def __cmp__(self, other): 44 return cmp(self.data, self.__cast(other)) 45 46 __hash__ = None 47 48 def __contains__(self, item): 49 return item in self.data 50 51 def __len__(self): 52 return len(self.data) 53 54 def __getitem__(self, i): 55 return self.data[i] 56 57 def __setitem__(self, i, item): 58 self.data[i] = item 59 60 def __delitem__(self, i): 61 del self.data[i] 62 63 def __getslice__(self, i, j): 64 i = max(i, 0) 65 j = max(j, 0) 66 return self.__class__(self.data[i:j]) 67 68 def __setslice__(self, i, j, other): 69 i = max(i, 0) 70 j = max(j, 0) 71 if isinstance(other, UserList): 72 self.data[i:j] = other.data 73 elif isinstance(other, type(self.data)): 74 self.data[i:j] = other 75 else: 76 self.data[i:j] = list(other) 77 78 def __delslice__(self, i, j): 79 i = max(i, 0) 80 j = max(j, 0) 81 del self.data[i:j] 82 83 def __add__(self, other): 84 if isinstance(other, UserList): 85 return self.__class__(self.data + other.data) 86 elif isinstance(other, type(self.data)): 87 return self.__class__(self.data + other) 88 else: 89 return self.__class__(self.data + list(other)) 90 91 def __radd__(self, other): 92 if isinstance(other, UserList): 93 return self.__class__(other.data + self.data) 94 elif isinstance(other, type(self.data)): 95 return self.__class__(other + self.data) 96 else: 97 return self.__class__(list(other) + self.data) 98 99 def __iadd__(self, other): 100 if isinstance(other, UserList): 101 self.data += other.data 102 elif isinstance(other, type(self.data)): 103 self.data += other 104 else: 105 self.data += list(other) 106 return self 107 108 def __mul__(self, n): 109 return self.__class__(self.data * n) 110 111 __rmul__ = __mul__ 112 113 def __imul__(self, n): 114 self.data *= n 115 return self 116 117 def append(self, item): 118 self.data.append(item) 119 120 def insert(self, i, item): 121 self.data.insert(i, item) 122 123 def pop(self, i = -1): 124 return self.data.pop(i) 125 126 def remove(self, item): 127 self.data.remove(item) 128 129 def count(self, item): 130 return self.data.count(item) 131 132 def index(self, item, *args): 133 return self.data.index(item, *args) 134 135 def reverse(self): 136 self.data.reverse() 137 138 def sort(self, *args, **kwds): 139 self.data.sort(*args, **kwds) 140 141 def extend(self, other): 142 if isinstance(other, UserList): 143 self.data.extend(other.data) 144 else: 145 self.data.extend(other)