|
@@ -39,7 +39,15 @@ class SmartList(list): |
|
|
self._children[id(child)] = (child, sliceinfo) |
|
|
self._children[id(child)] = (child, sliceinfo) |
|
|
return child |
|
|
return child |
|
|
|
|
|
|
|
|
# def __setslice__(self, start, stop): |
|
|
|
|
|
|
|
|
def __setslice__(self, start, stop, iterable): |
|
|
|
|
|
obj = list(iterable) |
|
|
|
|
|
super(SmartList, self).__setslice__(start, stop, obj) |
|
|
|
|
|
diff = len(obj) - stop + start |
|
|
|
|
|
for child, (ch_start, ch_stop, step) in self._children.itervalues(): |
|
|
|
|
|
if ch_start >= stop: |
|
|
|
|
|
self._children[id(child)][1][0] += diff |
|
|
|
|
|
if ch_stop >= stop and ch_stop != sys.maxint: |
|
|
|
|
|
self._children[id(child)][1][1] += diff |
|
|
|
|
|
|
|
|
def append(self, obj): |
|
|
def append(self, obj): |
|
|
super(SmartList, self).append(obj) |
|
|
super(SmartList, self).append(obj) |
|
@@ -54,6 +62,9 @@ class _ListProxy(list): |
|
|
self._parent = parent |
|
|
self._parent = parent |
|
|
self._sliceinfo = sliceinfo |
|
|
self._sliceinfo = sliceinfo |
|
|
|
|
|
|
|
|
|
|
|
def __repr__(self): |
|
|
|
|
|
return repr(self._render()) |
|
|
|
|
|
|
|
|
def __len__(self): |
|
|
def __len__(self): |
|
|
return (self._stop - self._start) / self._step |
|
|
return (self._stop - self._start) / self._step |
|
|
|
|
|
|
|
@@ -69,6 +80,12 @@ class _ListProxy(list): |
|
|
def __getslice__(self, start, stop): |
|
|
def __getslice__(self, start, stop): |
|
|
return self._render()[start:stop] |
|
|
return self._render()[start:stop] |
|
|
|
|
|
|
|
|
|
|
|
def __setitem__(self, index, obj): |
|
|
|
|
|
self._parent[self._start + index] = obj |
|
|
|
|
|
|
|
|
|
|
|
def __setslice__(self, start, stop, iterable): |
|
|
|
|
|
self._parent[self._start + start:self._start + stop] = iterable |
|
|
|
|
|
|
|
|
@property |
|
|
@property |
|
|
def _start(self): |
|
|
def _start(self): |
|
|
return self._sliceinfo[0] |
|
|
return self._sliceinfo[0] |
|
|