[Zope3-checkins] CVS: Zope3/src/zope/app/component - globalinterfaceservice.py:1.12

Jeremy Hylton jeremy@zope.com
Sun, 22 Jun 2003 16:18:29 -0400


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

Modified Files:
	globalinterfaceservice.py 
Log Message:
Add items() to IInterfaceService.

Refactor the test suite so that it can be used by multiple implementations of IInterfaceService.
Implement other search methods in terms of items(), because it is the most generic.


=== Zope3/src/zope/app/component/globalinterfaceservice.py 1.11 => 1.12 ===
--- Zope3/src/zope/app/component/globalinterfaceservice.py:1.11	Sat Jun  7 02:37:21 2003
+++ Zope3/src/zope/app/component/globalinterfaceservice.py	Sun Jun 22 16:17:59 2003
@@ -14,6 +14,7 @@
 """
 $Id$
 """
+from __future__ import generators
 
 __metaclass__ = type
 
@@ -41,30 +42,23 @@
         else:
             return default
 
-    def searchInterfaceIds(self, search_string='', base=None):
-        result = []
-
-        data = self.__data
-        search_string = search_string.lower()
-
-        for id in data:
-            interface, doc = data[id]
-
+    def searchInterface(self, search_string=None, base=None):
+        return [t[1] for t in self.items(search_string, base)]
+    
+    def searchInterfaceIds(self, search_string=None, base=None):
+        return [t[0] for t in self.items(search_string, base)]
+
+    def items(self, search_string=None, base=None):
+        if search_string:
+            search_string = search_string.lower()
+            
+        for id, (interface, doc) in self.__data.items():
             if search_string:
                 if doc.find(search_string) < 0:
                     continue
-
             if base is not None and not interface.extends(base, 0):
                 continue
-
-            result.append(id)
-
-        return result
-
-    def searchInterface(self, search_string='', base=None):
-        data = self.__data
-        return [data[id][0]
-                for id in self.searchInterfaceIds(search_string, base)]
+            yield id, interface
 
     def _getAllDocs(self,interface):
         docs = [str(interface.__name__).lower(),