[Zodb-checkins] CVS: Zope3/src/zope/interface - implementor.py:1.3

Jim Fulton jim@zope.com
Fri, 21 Mar 2003 16:06:47 -0500


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

Modified Files:
	implementor.py 
Log Message:
Modified the ImplementorRegistry so we can pass a dictionary to be
used to store regtered data. This allows us to pass a PersistentDict
and thus get the registry to work with persistence.

Added a getRegistered method, which we need to get data for a specific
interface without "deheriting" data for more specific interfaces.


=== Zope3/src/zope/interface/implementor.py 1.2 => 1.3 ===
--- Zope3/src/zope/interface/implementor.py:1.2	Wed Dec 25 09:13:42 2002
+++ Zope3/src/zope/interface/implementor.py	Fri Mar 21 16:06:47 2003
@@ -36,8 +36,10 @@
     # Where the registered provides is what was registered and
     # provided may be some base interface
 
-    def __init__(self):
-        self._reg = {}
+    def __init__(self, data=None):
+        if data is None:
+            data = {}
+        self._reg = data
 
     def _registerAllProvided(self, primary_provide, object, provide):
         # Registers a component using (require, provide) as a key.
@@ -70,12 +72,24 @@
 
         self._registerAllProvided(provide, object, provide)
 
-    def get(self, provide, default=None):
+    def getRegistered(self, interface, default=None):
+        """Find the component registered exactly for the interface
         """
-        Finds a registered component that provides the given interface.
-        Returns None if not found.
+        c = self._reg.get(interface)
+        if c is not None and c[0] is interface:
+            return c[1]
+
+        return default
+        
+
+    def get(self, interface, default=None):
+        """Find the component registered for the interface
+
+        A component may be returned if it was registered fgor a more
+        specific interface.
+        
         """
-        c = self._reg.get(provide)
+        c = self._reg.get(interface)
         if c is not None:
             return c[1]