src/pyams_catalog/query.py
changeset 1 5add0249012c
child 3 7c6f10ffdda0
equal deleted inserted replaced
0:15b51dd45bab 1:5add0249012c
       
     1 #
       
     2 # Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
       
     3 # All Rights Reserved.
       
     4 #
       
     5 # This software is subject to the provisions of the Zope Public License,
       
     6 # Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
       
     7 # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
       
     8 # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
       
     9 # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
       
    10 # FOR A PARTICULAR PURPOSE.
       
    11 #
       
    12 
       
    13 __docformat__ = 'restructuredtext'
       
    14 
       
    15 
       
    16 # import standard library
       
    17 
       
    18 # import interfaces
       
    19 from zope.intid.interfaces import IIntIds
       
    20 
       
    21 # import packages
       
    22 from hypatia.query import Query
       
    23 from pyams_utils.registry import query_utility
       
    24 
       
    25 
       
    26 class CatalogResultSet(object):
       
    27     """Catalog query result set wrapper"""
       
    28 
       
    29     def __init__(self, query):
       
    30         self.query = query
       
    31         self.intids = query_utility(IIntIds)
       
    32 
       
    33     def __iter__(self):
       
    34         query = self.query
       
    35         if isinstance(query, Query):
       
    36             query = query.execute()
       
    37         if isinstance(query, tuple):
       
    38             query = query[1]
       
    39         for oid in query:
       
    40             yield self.intids.queryObject(oid)