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

Jim Fulton jim at zope.com
Thu Oct 16 17:43:09 EDT 2003


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

Modified Files:
      Tag: adaptergeddon-branch
	adapter.py 
Log Message:
Updated the global adapter service to use the new adapter machinery.


=== Zope3/src/zope/component/adapter.py 1.4 => 1.4.28.1 ===
--- Zope3/src/zope/component/adapter.py:1.4	Tue Jun  3 10:18:45 2003
+++ Zope3/src/zope/component/adapter.py	Thu Oct 16 17:42:38 2003
@@ -17,7 +17,7 @@
 __metaclass__ = type
 import sys
 from zope.interface import implements
-from zope.interface.adapter import AdapterRegistry
+from zope.interface.surrogate import SurrogateRegistry
 from zope.component.exceptions import ComponentLookupError
 from zope.component.interfaces import IGlobalAdapterService
 import warnings
@@ -27,9 +27,10 @@
     implements(IGlobalAdapterService)
 
     def __init__(self):
-        self.__adapters = {}
+        self.__adapters = SurrogateRegistry()
 
-    def provideAdapter(self, forInterface, providedInterface, maker, name=''):
+    def provideAdapter(self,
+                       forInterface, providedInterface, maker, name=None):
         """see IGlobalAdapterService interface"""
 
         if not isinstance(maker, (list, tuple)):
@@ -41,14 +42,10 @@
             raise TypeError("The registered component callable is not "
                             "callable")
 
-        registry = self.__adapters.get(name)
-        if registry is None:
-            registry = AdapterRegistry()
-            self.__adapters[name] = registry
+        self.__adapters.provideAdapter(forInterface, providedInterface, maker,
+                                       name)
 
-        registry.register(forInterface, providedInterface, maker)
-
-    def getAdapter(self, object, interface, name=''):
+    def getAdapter(self, object, interface, name=None):
         """see IAdapterService interface"""
         result = self.queryAdapter(object, interface, name=name)
         if result is None:
@@ -65,7 +62,7 @@
         return result
 
 
-    def queryAdapter(self, object, interface, default=None, name=''):
+    def queryAdapter(self, object, interface, default=None, name=None):
         """see IAdapterService interface"""
         if name:
             warnings.warn("The name argument to queryAdapter is deprecated",
@@ -96,24 +93,16 @@
         if interface.isImplementedBy(object):
             return object
 
-        return self.queryNamedAdapter(object, interface, name, default)
+        return self.__adapters.queryAdapter(object, interface, default)
 
     def queryNamedAdapter(self, object, interface, name, default=None):
         """see IAdapterService interface"""
-        registry = self.__adapters.get(name)
-        if registry is None:
-            return default
-
-        makers = registry.getForObject(object, interface)
-
-        if makers is None:
-            return default
-
-        result = object
-        for maker in makers:
-            result = maker(result)
+        if name:
+            return self.__adapters.queryNamedAdapter(
+                object, interface, name, default)
+        return self.__adapters.queryAdapter(object, interface, default)
 
-        return result
+    
 
     def getRegisteredMatching(self,
                               for_interfaces=None,
@@ -121,23 +110,13 @@
                               name = None,
                               ):
 
-        if name is not None:
-            registry = self.__adapters.get(name)
-            if registry is None:
-                return ()
-            return [(name, for_, provided, data)
-                    for (for_, provided, data)
-                    in registry.getRegisteredMatching(for_interfaces,
-                                                      provided_interfaces)
-                    ]
-
-        result = []
-        for name in self.__adapters:
-            r = self.getRegisteredMatching(
-                for_interfaces, provided_interfaces, name)
-            result.extend(r)
-
-        return result
+        return [(name, required, provided, factories)
+                for (required, provided, with, name, factories)
+                in self.__adapters.getRegisteredMatching(
+                      for_interfaces,
+                      provided_interfaces,
+                      name)
+                ]
 
     _clear = __init__
 




More information about the Zope3-Checkins mailing list