[Checkins] SVN: z3c.batching/trunk/src/z3c/batching/ Handle slices as input of __getitem__ in Py3.

Albertas Agejevas cvs-admin at zope.org
Mon Feb 25 12:16:49 UTC 2013


Log message for revision 129782:
  Handle slices as input of __getitem__ in Py3.
  

Changed:
  U   z3c.batching/trunk/src/z3c/batching/batch.py
  U   z3c.batching/trunk/src/z3c/batching/subset.py

-=-
Modified: z3c.batching/trunk/src/z3c/batching/batch.py
===================================================================
--- z3c.batching/trunk/src/z3c/batching/batch.py	2013-02-25 12:15:37 UTC (rev 129781)
+++ z3c.batching/trunk/src/z3c/batching/batch.py	2013-02-25 12:16:48 UTC (rev 129782)
@@ -108,6 +108,8 @@
 
     def __getitem__(self, key):
         """See zope.interface.common.sequence.IMinimalSequence"""
+        if isinstance(key, slice):
+            return self.__getslice__(key.start, key.stop)
         if key >= self._trueSize:
             raise IndexError('batch index out of range')
         return self.sequence[self.start + key]
@@ -128,6 +130,8 @@
             return False
 
     def __getslice__(self, i, j):
+        i = 0 if i is None else i
+        j = self._trueSize if j is None else j
         if j > self.end:
             j = self._trueSize
 
@@ -164,6 +168,8 @@
         return self.total
 
     def __getitem__(self, key):
+        if isinstance(key, slice):
+            return self.__getslice__(key.start, key.stop)
         if key not in self._batches:
             if key < 0:
                 key = self.total + key
@@ -178,6 +184,8 @@
             raise IndexError(key)
 
     def __getslice__(self, i, j):
+        i = 0 if i is None else i
+        j = self.total if j is None else j
         j = min(j, self.total)
         return [self[idx] for idx in range(i, j)]
 

Modified: z3c.batching/trunk/src/z3c/batching/subset.py
===================================================================
--- z3c.batching/trunk/src/z3c/batching/subset.py	2013-02-25 12:15:37 UTC (rev 129781)
+++ z3c.batching/trunk/src/z3c/batching/subset.py	2013-02-25 12:16:48 UTC (rev 129782)
@@ -87,6 +87,8 @@
 
     def __getitem__(self, key):
         """See zope.interface.common.sequence.IMinimalSequence"""
+        if isinstance(key, slice):
+            return self.__getslice__(key.start, key.stop)
         if key >= self._trueSize:
             raise IndexError('batch index out of range')
         return self.sequence[key]



More information about the checkins mailing list