[Zope3-checkins] CVS: Zope3/src/zope/component - adapter.py:1.8

Jim Fulton jim at zope.com
Mon Mar 15 15:42:54 EST 2004


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

Modified Files:
	adapter.py 
Log Message:
Factory semantics are now provided by the adapter service, rather than
the underlying adapter registry. These semantics are provided in a
mix-in class.

Only a single factory can be provided.

Changed the registration api to be consistent with the underlying
adapter registry api and, in general, to be simpler.


=== Zope3/src/zope/component/adapter.py 1.7 => 1.8 ===
--- Zope3/src/zope/component/adapter.py:1.7	Mon Mar  8 12:26:56 2004
+++ Zope3/src/zope/component/adapter.py	Mon Mar 15 15:42:23 2004
@@ -16,7 +16,7 @@
 
 __metaclass__ = type
 import sys
-from zope.interface import implements
+from zope.interface import implements, providedBy
 from zope.interface.adapter import AdapterRegistry
 from zope.component.exceptions import ComponentLookupError
 from zope.component.interfaces import IAdapterService
@@ -25,22 +25,26 @@
 
 class IGlobalAdapterService(IAdapterService):
 
-    def provideAdapter(required, provided, factories, name='', with=()):
-        """Provide an adapter
+    def register(required, provided, name, factory):
+        """Register an adapter factory
 
-        An adapter provides an interface for objects that have another
-        interface.
-
-        XXX: Arguments must be updated.
-        Arguments:
-
-        forInterface -- The interface the adapter provides an interface for.
-
-        providedInterface -- The provided interface
+        :Parameters:
+          - `required`: a sequence of specifications for objects to be
+             adapted. 
+          - `provided`: The interface provided by the adapter
+          - `name`: The adapter name
+          - `factory`: The object used to compute the adapter
+        """
 
-        maker -- a sequence of factories that are used to create the adapter.
-        The first factory is called with the object to be adapted, subsequent
-        factories are called with the results of the previous factory.
+    def subscribe(required, provided, factory):
+        """Register a subscriber factory
+        
+        :Parameters:
+          - `required`: a sequence of specifications for objects to be
+             adapted. 
+          - `provided`: The interface provided by the adapter
+          - `name`: The adapter name
+          - `factory`: The object used to compute the subscriber
         """
 
     def getRegisteredMatching(required=None,
@@ -60,7 +64,32 @@
           - registered data
         """
 
-class GlobalAdapterService(AdapterRegistry, GlobalService):
+class AdapterService(AdapterRegistry):
 
-    implements(IGlobalAdapterService)
+    implements(IAdapterService)
+
+    def queryAdapter(self, object, interface, default=None):
+        return self.queryNamedAdapter(object, interface, '', default)
 
+    def queryNamedAdapter(self, object, interface, name='', default=None):
+        factory = self.lookup1(providedBy(object), interface, name)
+        if factory is not None:
+            return factory(object)
+        
+        return default
+
+    def queryMultiAdapter(self, objects, interface, name='', default=None):
+        factory = self.lookup(map(providedBy, objects), interface, name)
+        if factory is not None:
+            return factory(*objects)
+
+        return default
+
+    def subscribers(self, objects, interface):
+        subscriptions = self.subscriptions(map(providedBy, objects), interface)
+        return [subscription(*objects) for subscription in subscriptions]
+    
+
+class GlobalAdapterService(AdapterService, GlobalService):
+
+    implements(IGlobalAdapterService)




More information about the Zope3-Checkins mailing list