[Zodb-checkins] CVS: Zope3/src/zope/interface - interfaces.py:1.6 type.py:1.5

Steve Alexander steve@cat-box.net
Thu, 30 Jan 2003 08:39:15 -0500


Update of /cvs-repository/Zope3/src/zope/interface
In directory cvs.zope.org:/tmp/cvs-serv20711

Modified Files:
	interfaces.py type.py 
Log Message:
added getTypesMatching() method to TypeRegistry.


=== Zope3/src/zope/interface/interfaces.py 1.5 => 1.6 ===
--- Zope3/src/zope/interface/interfaces.py:1.5	Wed Jan 29 13:48:52 2003
+++ Zope3/src/zope/interface/interfaces.py	Thu Jan 30 08:38:41 2003
@@ -289,6 +289,12 @@
         """Get all registered objects for types that object implements.
         """
 
+    def getTypesMatching(interface):
+        """Get all registered interfaces matching the given interface
+
+        Returns a sequence of all interfaces registered that extend
+        or are equal to the given interface.
+        """
 
 class IAdapterRegistry(Interface):
     """Adapter-style registry
@@ -377,7 +383,7 @@
         - the object registered specifically for the required and
           provided interfaces.
 
-        To understand hopw the matching works, imagine that we have
+        To understand how the matching works, imagine that we have
         interfaces R1, R2, P1, and P2. R2 extends R1. P2 extends P1.
         We've registered C to require R1 and provide P2.  Given this,
         if we call getRegisteredMatching:


=== Zope3/src/zope/interface/type.py 1.4 => 1.5 ===
--- Zope3/src/zope/interface/type.py:1.4	Wed Jan 29 13:48:52 2003
+++ Zope3/src/zope/interface/type.py	Thu Jan 30 08:38:41 2003
@@ -43,7 +43,7 @@
     def __init__(self, data=None):
         if data is None:
             data = {}
-            
+
         self._reg = data
 
     def register(self, interface, object):
@@ -90,3 +90,14 @@
         # account implementation registries for objects that can't
         # have '__implements__' attributes.
         return self.getAll(getattr(object, '__implements__', None))
+
+    def getTypesMatching(self, interface):
+        if interface is None:
+            return self._reg.keys()
+
+        result = []
+        for k in self._reg:
+            if k is None or k.extends(interface, strict=False):
+                result.append(k)
+        return result
+