[Zope3-checkins] SVN: Zope3/branches/jim-index-restructure-2004-12/src/zope/app/intid/ Added an iteration protocol.

Jim Fulton jim at zope.com
Thu Dec 9 11:40:03 EST 2004


Log message for revision 28596:
  Added an iteration protocol.
  

Changed:
  U   Zope3/branches/jim-index-restructure-2004-12/src/zope/app/intid/__init__.py
  U   Zope3/branches/jim-index-restructure-2004-12/src/zope/app/intid/interfaces.py
  U   Zope3/branches/jim-index-restructure-2004-12/src/zope/app/intid/tests.py

-=-
Modified: Zope3/branches/jim-index-restructure-2004-12/src/zope/app/intid/__init__.py
===================================================================
--- Zope3/branches/jim-index-restructure-2004-12/src/zope/app/intid/__init__.py	2004-12-08 23:35:13 UTC (rev 28595)
+++ Zope3/branches/jim-index-restructure-2004-12/src/zope/app/intid/__init__.py	2004-12-09 16:40:03 UTC (rev 28596)
@@ -59,6 +59,9 @@
     def items(self):
         return list(self.refs.items())
 
+    def __iter__(self):
+        return self.refs.iterkeys()
+
     def getObject(self, id):
         return self.refs[id]()
 

Modified: Zope3/branches/jim-index-restructure-2004-12/src/zope/app/intid/interfaces.py
===================================================================
--- Zope3/branches/jim-index-restructure-2004-12/src/zope/app/intid/interfaces.py	2004-12-08 23:35:13 UTC (rev 28595)
+++ Zope3/branches/jim-index-restructure-2004-12/src/zope/app/intid/interfaces.py	2004-12-09 16:40:03 UTC (rev 28596)
@@ -27,6 +27,10 @@
         Return the default if the object isn't registered
         """
 
+    def __iter__():
+        """Return an iteration on the ids"""
+        
+
 class IIntIdsSet(Interface):
 
     def register(ob):

Modified: Zope3/branches/jim-index-restructure-2004-12/src/zope/app/intid/tests.py
===================================================================
--- Zope3/branches/jim-index-restructure-2004-12/src/zope/app/intid/tests.py	2004-12-08 23:35:13 UTC (rev 28595)
+++ Zope3/branches/jim-index-restructure-2004-12/src/zope/app/intid/tests.py	2004-12-09 16:40:03 UTC (rev 28596)
@@ -98,11 +98,13 @@
 
         self.assertEquals(len(u), 0)
         self.assertEquals(u.items(), [])
+        self.assertEquals(list(u), [])
 
         uid = u.register(obj)
         ref = KeyReferenceToPersistent(obj)
         self.assertEquals(len(u), 1)
         self.assertEquals(u.items(), [(uid, ref)])
+        self.assertEquals(list(u), [uid])
 
         obj2 = P()
         obj2.__parent__ = obj
@@ -115,6 +117,11 @@
         result.sort()
         expected.sort()
         self.assertEquals(result, expected)
+        result = list(u)
+        expected = [uid, uid2]
+        result.sort()
+        expected.sort()
+        self.assertEquals(result, expected)
 
         u.unregister(obj)
         u.unregister(obj2)



More information about the Zope3-Checkins mailing list