# HG changeset patch # User Thierry Florac # Date 1426774704 -3600 # Node ID 5add0249012c203ae9c06e2877848a809adf024c # Parent 15b51dd45bab73b3ad0f6216c12ca8c42e5257ed Added catalog result set diff -r 15b51dd45bab -r 5add0249012c src/pyams_catalog/query.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/pyams_catalog/query.py Thu Mar 19 15:18:24 2015 +0100 @@ -0,0 +1,40 @@ +# +# Copyright (c) 2008-2015 Thierry Florac +# All Rights Reserved. +# +# This software is subject to the provisions of the Zope Public License, +# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. +# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED +# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS +# FOR A PARTICULAR PURPOSE. +# + +__docformat__ = 'restructuredtext' + + +# import standard library + +# import interfaces +from zope.intid.interfaces import IIntIds + +# import packages +from hypatia.query import Query +from pyams_utils.registry import query_utility + + +class CatalogResultSet(object): + """Catalog query result set wrapper""" + + def __init__(self, query): + self.query = query + self.intids = query_utility(IIntIds) + + def __iter__(self): + query = self.query + if isinstance(query, Query): + query = query.execute() + if isinstance(query, tuple): + query = query[1] + for oid in query: + yield self.intids.queryObject(oid)