[Zope3-checkins] SVN: Zope3/trunk/src/zope/interface/adapter. Allow None as a provided interface when registering or looking up

Jim Fulton jim at zope.com
Tue May 25 15:23:56 EDT 2004


Log message for revision 24969:
Allow None as a provided interface when registering or looking up
subscribers. We call these handlers, as they do all of their work when
they are called, rather than creating objects that provide some
interesting interface.



-=-
Modified: Zope3/trunk/src/zope/interface/adapter.py
===================================================================
--- Zope3/trunk/src/zope/interface/adapter.py	2004-05-25 19:06:25 UTC (rev 24968)
+++ Zope3/trunk/src/zope/interface/adapter.py	2004-05-25 19:23:56 UTC (rev 24969)
@@ -479,13 +479,18 @@
         else:
             required = self._null
             with = ()
-        
+
+        if provided is None:
+            provided = self._default
+            
         required._subscriptionAdaptTo(provided, value, with)
 
 
     def subscriptions(self, required, provided):
+        if provided is None:
+            provided = self._default
+
         order = len(required)
-        
         if order == 1:
             # Simple subscriptions:
             s = self.get(required[0])

Modified: Zope3/trunk/src/zope/interface/adapter.txt
===================================================================
--- Zope3/trunk/src/zope/interface/adapter.txt	2004-05-25 19:06:25 UTC (rev 24968)
+++ Zope3/trunk/src/zope/interface/adapter.txt	2004-05-25 19:23:56 UTC (rev 24969)
@@ -331,3 +331,20 @@
   ['sub1', 'sub2']
   >>> registry.subscriptions([], IP2)
   ['sub2']
+
+Handlers
+--------
+
+A handler is a subscriber factory that doesn't produce any normal
+output. It returns None.  A handler is unlike adapters in that it does
+all of it;s work the factory is called.
+
+To register a handler, simply provide None as the provided interface:
+
+  >>> def handler(event):
+  ...     print 'handler', event
+  
+  >>> registry.subscribe([IR1], None, handler)
+  >>> registry.subscriptions([IR1], None) == [handler]
+  True
+




More information about the Zope3-Checkins mailing list