src/pyams_catalog/query.py
changeset 44 32052893d519
parent 21 464671eede98
equal deleted inserted replaced
43:9fff3eaacd26 44:32052893d519
    10 # FOR A PARTICULAR PURPOSE.
    10 # FOR A PARTICULAR PURPOSE.
    11 #
    11 #
    12 
    12 
    13 __docformat__ = 'restructuredtext'
    13 __docformat__ = 'restructuredtext'
    14 
    14 
    15 
    15 from hypatia.query import Query
    16 # import standard library
       
    17 
       
    18 # import interfaces
       
    19 from zope.intid.interfaces import IIntIds
    16 from zope.intid.interfaces import IIntIds
    20 
    17 
    21 # import packages
       
    22 from hypatia.query import Query
       
    23 from pyams_utils.registry import query_utility
    18 from pyams_utils.registry import query_utility
    24 
    19 
    25 
    20 
    26 class CatalogResultSet(object):
    21 class CatalogResultSet(object):
    27     """Catalog query result set wrapper"""
    22     """Catalog query result set wrapper"""
    50                 else:
    45                 else:
    51                     yield oid
    46                     yield oid
    52         for item in self.last:
    47         for item in self.last:
    53             yield item
    48             yield item
    54 
    49 
       
    50     def __len__(self):
       
    51         return len(self.first) + len(self.query) + len(self.last)
       
    52 
    55     def prepend(self, items):
    53     def prepend(self, items):
    56         if isinstance(items, CatalogResultSet):
    54         insert = self.first.insert
    57             items = list(items)
    55         for index, item in enumerate(items):
    58         self.first.extend(items)
    56             insert(index, item)
    59 
    57 
    60     def append(self, items):
    58     def append(self, items):
    61         if isinstance(items, CatalogResultSet):
    59         append = self.last.append
    62             items = list(items)
    60         for item in items:
    63         self.last.extend(items)
    61             append(item)
    64 
    62 
    65 
    63 
    66 def or_(source, added):
    64 def or_(source, added):
    67     """Combine two queries with 'or'"""
    65     """Combine two queries with 'or'"""
    68     if source is None:
    66     if source is None: