Commit db55f40c authored by Julien Muchembled's avatar Julien Muchembled Committed by Tatuya Kamada

HBTreeFolder2: implement slicing of object{Ids,Items,Values} results

This is required for ERP5Site_checkDataWithScript script (erp5_core BT).
parent 1e64ade6
...@@ -97,6 +97,8 @@ class HBTreeObjectIds(object): ...@@ -97,6 +97,8 @@ class HBTreeObjectIds(object):
return self._keys() return self._keys()
def __getitem__(self, item): def __getitem__(self, item):
if isinstance(item, slice):
return map(self.__getitem__, xrange(*item.indices(self._count())))
if item < 0: if item < 0:
item += self._count() item += self._count()
i = self._index i = self._index
...@@ -119,6 +121,8 @@ class HBTreeObjectItems(HBTreeObjectIds): ...@@ -119,6 +121,8 @@ class HBTreeObjectItems(HBTreeObjectIds):
return ((x, getOb(x)) for x in self._keys()) return ((x, getOb(x)) for x in self._keys())
def __getitem__(self, item): def __getitem__(self, item):
if isinstance(item, slice):
return map(self.__getitem__, xrange(*item.indices(self._count())))
object_id = HBTreeObjectIds.__getitem__(self, item) object_id = HBTreeObjectIds.__getitem__(self, item)
return object_id, self._tree._getOb(object_id) return object_id, self._tree._getOb(object_id)
ContainerAssertions[HBTreeObjectItems] = 1 ContainerAssertions[HBTreeObjectItems] = 1
...@@ -130,6 +134,8 @@ class HBTreeObjectValues(HBTreeObjectIds): ...@@ -130,6 +134,8 @@ class HBTreeObjectValues(HBTreeObjectIds):
return (getOb(x) for x in self._keys()) return (getOb(x) for x in self._keys())
def __getitem__(self, item): def __getitem__(self, item):
if isinstance(item, slice):
return map(self.__getitem__, xrange(*item.indices(self._count())))
return self._tree._getOb(HBTreeObjectIds.__getitem__(self, item)) return self._tree._getOb(HBTreeObjectIds.__getitem__(self, item))
ContainerAssertions[HBTreeObjectValues] = 1 ContainerAssertions[HBTreeObjectValues] = 1
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment