[Zope3-checkins] CVS: Zope3/src/zope/app/catalog - catalog.py:1.1.2.6

Anthony Baxter anthony@interlink.com.au
Sat, 12 Jul 2003 23:13:49 -0400


Update of /cvs-repository/Zope3/src/zope/app/catalog
In directory cvs.zope.org:/tmp/cvs-serv31466

Modified Files:
      Tag: melb-2003-content-catalog-branch
	catalog.py 
Log Message:
ResultSet is now a class that implements the __iter__ protocol (and __len__).
It still does 'lazy loading' of the objects - if you get back 24,000 objects
and only load the first 20, the rest aren't brought into memory.

minor changes to test suite to match this.



=== Zope3/src/zope/app/catalog/catalog.py 1.1.2.5 => 1.1.2.6 ===
--- Zope3/src/zope/app/catalog/catalog.py:1.1.2.5	Sat Jul 12 22:54:48 2003
+++ Zope3/src/zope/app/catalog/catalog.py	Sat Jul 12 23:13:15 2003
@@ -23,10 +23,21 @@
 
 from zope.app.interfaces.catalog.catalog import ICatalogView, ICatalog
 
-def ResultSet(hubidset, hub):
-    for hubid in hubidset:
-        obj = hub.getObject(hubid)
-        yield obj
+class ResultSet:
+    "Lazily accessed set of objects"
+
+    def __init__(self, hubidset, hub):
+        self.hubidset = hubidset
+        self.hub = hub
+
+    def __len__(self):
+        return len(self.hubidset)
+
+    def __iter__(self):
+        for hubid in self.hubidset:
+            obj = self.hub.getObject(hubid)
+            yield obj
+
 
 class Catalog(Persistent, SampleContainer):