summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHeiko Noordhof <hkoof@xs4all.nl>2014-10-16 10:21:49 +0200
committerHeiko Noordhof <hkoof@xs4all.nl>2014-10-17 09:50:00 +0200
commitba1c39341504922d4a7af8453d929de71ad86c13 (patch)
treee8bf984f8795b63d14549e2e8ae4077458d7aa1f
parent4b65912ac1e5aaac4c7794f41fca2db655e9d9d4 (diff)
downloadurwid-ba1c39341504922d4a7af8453d929de71ad86c13.tar.gz
turn deprecated slice methods into wrappers
__delslice__() and __setslice__() are deprecated as of python v2.6 [1] and urwid does not support python versions pre-v2.6 (anymore). Making these methods wrappers of __delitem__() and __setitem__() de-duplicates code (and doctest's) [1] https://docs.python.org/2.6/reference/datamodel.html
-rwxr-xr-xurwid/monitored_list.py45
1 files changed, 2 insertions, 43 deletions
diff --git a/urwid/monitored_list.py b/urwid/monitored_list.py
index a1a6326..028e082 100755
--- a/urwid/monitored_list.py
+++ b/urwid/monitored_list.py
@@ -319,51 +319,10 @@ class MonitoredFocusList(MonitoredList):
if not PYTHON3:
def __delslice__(self, i, j):
- """
- >>> def modified(indices, new_items):
- ... print "range%r <- %r" % (indices, list(new_items))
- >>> ml = MonitoredFocusList([0,1,2,3,4], focus=2)
- >>> ml.set_validate_contents_modified(modified)
- >>> del ml[3:5]
- range(3, 5, 1) <- []
- >>> ml
- MonitoredFocusList([0, 1, 2], focus=2)
- >>> del ml[:1]
- range(0, 1, 1) <- []
- >>> ml
- MonitoredFocusList([1, 2], focus=1)
- >>> del ml[1:]; ml
- range(1, 2, 1) <- []
- MonitoredFocusList([1], focus=0)
- >>> del ml[:]; ml
- range(0, 1, 1) <- []
- MonitoredFocusList([], focus=None)
- """
- focus = self._adjust_focus_on_contents_modified(slice(i, j))
- rval = super(MonitoredFocusList, self).__delslice__(i, j)
- self._set_focus(focus)
- return rval
+ return self.__delitem__(slice(i,j))
def __setslice__(self, i, j, y):
- """
- >>> ml = MonitoredFocusList([0,1,2,3,4], focus=2)
- >>> ml[3:5] = [-1]; ml
- MonitoredFocusList([0, 1, 2, -1], focus=2)
- >>> ml[0:1] = []; ml
- MonitoredFocusList([1, 2, -1], focus=1)
- >>> ml[1:] = [3, 4]; ml
- MonitoredFocusList([1, 3, 4], focus=1)
- >>> ml[1:] = [2]; ml
- MonitoredFocusList([1, 2], focus=1)
- >>> ml[0:1] = [9,9,9]; ml
- MonitoredFocusList([9, 9, 9, 2], focus=3)
- >>> ml[:] = []; ml
- MonitoredFocusList([], focus=None)
- """
- focus = self._adjust_focus_on_contents_modified(slice(i, j), y)
- rval = super(MonitoredFocusList, self).__setslice__(i, j, y)
- self._set_focus(focus)
- return rval
+ return self.__setitem__(slice(i, j), y)
def __imul__(self, n):
"""