98 if keepafter > 0: |
99 if keepafter > 0: |
99 del self[:keepafter] |
100 del self[:keepafter] |
100 |
101 |
101 __iadd__ = extend |
102 __iadd__ = extend |
102 |
103 |
|
104 |
|
105 class RepeatList(object): |
|
106 """fake a list with the same element in each row""" |
|
107 __slots__ = ('_size', '_item') |
|
108 def __init__(self, size, item): |
|
109 self._size = size |
|
110 self._item = item |
|
111 def __len__(self): |
|
112 return self._size |
|
113 def __nonzero__(self): |
|
114 return self._size |
|
115 def __iter__(self): |
|
116 return repeat(self._item, self._size) |
|
117 def __getitem__(self, index): |
|
118 return self._item |
|
119 def __getslice__(self, i, j): |
|
120 # XXX could be more efficient, but do we bother? |
|
121 return ([self._item] * self._size)[i:j] |
|
122 def __add__(self, other): |
|
123 if isinstance(other, RepeatList): |
|
124 if other._item == self._item: |
|
125 return RepeatList(self._size + other._size, self._item) |
|
126 return ([self._item] * self._size) + other[:] |
|
127 return ([self._item] * self._size) + other |
|
128 def __radd__(self, other): |
|
129 if isinstance(other, RepeatList): |
|
130 if other._item == self._item: |
|
131 return RepeatList(self._size + other._size, self._item) |
|
132 return other[:] + ([self._item] * self._size) |
|
133 return other[:] + ([self._item] * self._size) |
|
134 def __eq__(self, other): |
|
135 if isinstance(other, RepeatList): |
|
136 return other._size == self.size and other._item == self.item |
|
137 return self[:] == other |
|
138 def pop(self, i): |
|
139 self._size -= 1 |
103 |
140 |
104 class UStringIO(list): |
141 class UStringIO(list): |
105 """a file wrapper which automatically encode unicode string to an encoding |
142 """a file wrapper which automatically encode unicode string to an encoding |
106 specifed in the constructor |
143 specifed in the constructor |
107 """ |
144 """ |