def test_None_is_smallest(self): t = self._makeOne() for i in range(999): # Make sure we multiple buckets t[i] = i * i t[None] = -1 for i in range(-99, 0): # Make sure we multiple buckets t[i] = i * i self.assertEqual(list(t), [None] + list(range(-99, 999))) self.assertEqual(list(t.values()), [-1] + [i * i for i in range(-99, 999)]) self.assertEqual(t[2], 4) self.assertEqual(t[-2], 4) self.assertEqual(t[None], -1) t[None] = -2 self.assertEqual(t[None], -2) t2 = t.__class__(t) del t[None] self.assertEqual(list(t), list(range(-99, 999))) if 'Py' in self.__class__.__name__: return from BTrees.OOBTree import difference, union, intersection self.assertEqual(list(difference(t2, t).items()), [(None, -2)]) self.assertEqual(list(union(t, t2)), list(t2)) self.assertEqual(list(intersection(t, t2)), list(t))
def test_None_is_smallest(self): t = self._makeOne() for i in range(999): # Make sure we multiple buckets t[i] = i*i t[None] = -1 for i in range(-99,0): # Make sure we multiple buckets t[i] = i*i self.assertEqual(list(t), [None] + list(range(-99, 999))) self.assertEqual(list(t.values()), [-1] + [i*i for i in range(-99, 999)]) self.assertEqual(t[2], 4) self.assertEqual(t[-2], 4) self.assertEqual(t[None], -1) t[None] = -2 self.assertEqual(t[None], -2) t2 = t.__class__(t) del t[None] self.assertEqual(list(t), list(range(-99, 999))) if 'Py' in self.__class__.__name__: return from BTrees.OOBTree import difference, union, intersection self.assertEqual(list(difference(t2, t).items()), [(None, -2)]) self.assertEqual(list(union(t, t2)), list(t2)) self.assertEqual(list(intersection(t, t2)), list(t))
def search_objects(self, query): """ Return list of objects which match all properties that are set (``not None``) using AND operator to all of them. Example: result = storage_handler.search_objects( DBPublication(isbn="azgabash") ) Args: query (obj): Object implementing proper interface with some of the properties set. Returns: list: List of matching objects or ``[]`` if no match was found. Raises: InvalidType: When the `query` doesn't implement required properties. """ self._check_obj_properties(query, "query") # AND operator between results final_result = None for result in self._get_subset_matches(query): if final_result is None: final_result = result continue final_result = intersection(final_result, result) # if no result is found, `final_result` is None, and I want [] if not final_result: return [] return list(final_result)
def __and__(self, other): return QuerySet(intersection(OOTreeSet(self), OOTreeSet(other)))
def intersection(self, *args): from BTrees.OOBTree import intersection return intersection(*args)
def intersection(self, *args): from BTrees.OLBTree import intersection return intersection(*args)