def _search_for_items(self, query):
     result = None
     if IItemSubscriber.providedBy(query) or valid_signature(query):
         sresult = set()
         if not isinstance(query, tuple):
             query = query.signature()
         for idx in self.indexes:
             sresult = sresult | set(
                 self._search_for_items({idx: query}))
         return sorted(tuple(sresult))
     # search for specific subscription relationship name:
     for (k, v) in query.items():
         if str(k) in self.indexes:
             idx = self.indexes[str(k)]
             if IItemSubscriber.providedBy(v):
                 signature = v.signature()
             elif isinstance(v, tuple) and len(v) == 2:
                 signature = v
             else:
                 raise ValueError('unable to obtain subscriber signature')
             if result is None:
                 result = set(idx.item_uids_for(signature))
             else:
                 result = result & set(idx.item_uids_for(signature))
     if not result:
         return ()
     return tuple(result)
 def _validate(self, value):
     if not (hasattr(value, '__len__') and hasattr(value, '__iter__')):
         raise ValueError('Value must be iterable')
     if not len(value) == 3:
         raise ValueError('Value must have length of exactly 3 elements')
     if not valid_signature(value[1]):
         raise ValueError('Invalid subscriber signature.')
     if not (isinstance(value[0], str) and isinstance(value[2], str)):
         raise ValueError('Invalid subscription description tuple.')
 def search(self, query):
     if isinstance(query, basestring):
         return self._search_for_subscribers(query)  # query: UID
     if IItemSubscriber.providedBy(query) or valid_signature(query):
         return self._search_for_items(query)  # query: sub or sig
     # query for named subscription relationships:
     k, v = query.items()[0]
     if IItemSubscriber.providedBy(v) or isinstance(v, tuple):
         return self._search_for_items(query)  # tuple of uids
     return self._search_for_subscribers(query)