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

Jim Fulton jim@zope.com
Wed, 29 Jan 2003 13:49:25 -0500


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

Modified Files:
	interfaces.py type.py 
Log Message:
Added an unregister method to type registries.

Also change __init__ to allow a mapping object to be passed. This
is to make it things like a persistent subclass possible.


=== Zope3/src/zope/interface/interfaces.py 1.4 => 1.5 ===
--- Zope3/src/zope/interface/interfaces.py:1.4	Wed Jan 29 12:03:33 2003
+++ Zope3/src/zope/interface/interfaces.py	Wed Jan 29 13:48:52 2003
@@ -266,6 +266,12 @@
         default object.
         """
 
+    def unregister(interface):
+        """Remove the registration for the given interface
+
+        If nothing is registered for the interface, the call is ignored.
+        """
+
     def get(interface, default=None):
         """Return the object registered for the given interface.
         """


=== Zope3/src/zope/interface/type.py 1.3 => 1.4 ===
--- Zope3/src/zope/interface/type.py:1.3	Mon Dec 30 09:00:48 2002
+++ Zope3/src/zope/interface/type.py	Wed Jan 29 13:48:52 2003
@@ -40,12 +40,23 @@
     # 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 register(self, interface, object):
         if interface is None or IInterface.isImplementedBy(interface):
             self._reg[interface] = object
+        else:
+            raise TypeError(
+                "The interface argument must be an interface (or None)")
+
+    def unregister(self, interface):
+        if interface is None or IInterface.isImplementedBy(interface):
+            if interface in self._reg:
+                del self._reg[interface]
         else:
             raise TypeError(
                 "The interface argument must be an interface (or None)")