[Zope-Checkins] CVS: Zope3/lib/python/Zope/ComponentArchitecture - GlobalAdapterService.py:1.3 GlobalResourceService.py:1.4 GlobalSkinService.py:1.3 GlobalUtilityService.py:1.4 GlobalViewService.py:1.5 IPlacefulComponentArchitecture.py:1.4 IViewService.py:1.3 __init__.py:1.7 IToIRegistry.py:NONE

Jim Fulton jim@zope.com
Thu, 1 Aug 2002 11:34:15 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/ComponentArchitecture
In directory cvs.zope.org:/tmp/cvs-serv4877/lib/python/Zope/ComponentArchitecture

Modified Files:
	GlobalAdapterService.py GlobalResourceService.py 
	GlobalSkinService.py GlobalUtilityService.py 
	GlobalViewService.py IPlacefulComponentArchitecture.py 
	IViewService.py __init__.py 
Removed Files:
	IToIRegistry.py 
Log Message:
Refactored and moved Zope.ComponentArchitecture.IToIRegistry into
Interface.Registry. This is only the first step. The tests pass and
Zope 3 runs, but there are a bunch of wrong dependencies that still
need to get cleaned up, which is my next task.



=== Zope3/lib/python/Zope/ComponentArchitecture/GlobalAdapterService.py 1.2 => 1.3 ===
 """adapter service
 """
 
-from IToIRegistry import IToIRegistry
+from Interface.Registry.AdapterRegistry import AdapterRegistry
 from Exceptions import ComponentLookupError
 from IAdapterService import IAdapterService
 from Zope.Proxy.ProxyIntrospection import removeAllProxies
@@ -42,10 +42,20 @@
     __implements__ = IGlobalAdapterService
     
     def __init__(self):
-        self.__adapters = IToIRegistry()
+        self.__adapters = AdapterRegistry()
     
     def provideAdapter(self, forInterface, providedInterface, maker):
         """see IGlobalAdapterService interface"""
+
+        if not isinstance(maker, (list, tuple)):
+            maker = [maker]
+        else:
+            maker = list(maker)
+
+        if not maker == filter(callable, maker):
+            raise TypeError("The registered component callable is not "
+                            "callable")
+        
         self.__adapters.register(forInterface, providedInterface, maker)
 
     def getAdapter(self, object, interface):


=== Zope3/lib/python/Zope/ComponentArchitecture/GlobalResourceService.py 1.3 => 1.4 ===
 $Id$
 """
 
-from IToIRegistry import DataRegistry
+from Interface.Registry.ImplementorRegistry import ImplementorRegistry
 from Exceptions import ComponentLookupError
 from Zope.ComponentArchitecture import getSkin
 from IResourceService import IResourceService
@@ -73,7 +73,7 @@
             if not layer: continue
             reg = layer.get(name, None)
             if reg is None: continue
-            factory = reg.get(None, type)
+            factory = reg.get(type)
             if factory is None:
                 continue
 
@@ -91,7 +91,7 @@
 
         reg = resources.get(name, None)
         if reg is None:
-            reg = resources[name] = DataRegistry()
+            reg = resources[name] = ImplementorRegistry()
 
         reg.register(type, factory)
 


=== Zope3/lib/python/Zope/ComponentArchitecture/GlobalSkinService.py 1.2 => 1.3 ===
 $Id$
 """
 
-from IToIRegistry import IToIRegistry
+from Interface.Registry.ImplementorRegistry import ImplementorRegistry
 from Exceptions import ComponentLookupError
 from ISkinService import ISkinService
-from IToIRegistry import DataRegistry
 from Zope.Proxy.ProxyIntrospection import removeAllProxies
 
 
@@ -48,17 +47,16 @@
         
         reg = self.__skins.get(name, None)
         if reg is None:
-            reg = self.__skins[name] = DataRegistry()
+            reg = self.__skins[name] = ImplementorRegistry()
 
         reg.register(view_type, layers)
 
     def getSkin(self, object, name, view_type):
         '''See interface ISkinService'''
 
-        clean_object=removeAllProxies(object)
         reg = self.__skins.get(name, None)
         if reg is not None:
-            layers = reg.getForObject(clean_object, view_type)
+            layers = reg.get(view_type)
             if layers is not None:
                 return layers
 


=== Zope3/lib/python/Zope/ComponentArchitecture/GlobalUtilityService.py 1.3 => 1.4 ===
 $Id$
 """
 
+from Interface.Registry.ImplementorRegistry import ImplementorRegistry
 from IUtilityService import IUtilityService
-from IToIRegistry import IRegistry
 from Exceptions import ComponentLookupError
 
 class IGlobalUtilityService(IUtilityService):
@@ -33,10 +33,15 @@
     __implements__=IGlobalUtilityService
     
     def __init__(self):
-        self.__utilities=IRegistry()
+        self.__utilities=ImplementorRegistry()
 
     def provideUtility(self, providedInterface, component):
         """See IGlobalUtilityService interface"""
+
+        if not providedInterface.isImplementedBy(component):
+            raise Invalid("The registered component doesn't implement "
+                          "the promised interface.")
+        
         self.__utilities.register(providedInterface, component)
 
     def getUtility(self, interface):
@@ -48,7 +53,7 @@
 
     def queryUtility(self, interface, default=None):
         """See IUtilityService interface"""
-        c = self.__utilities.get(None, interface)
+        c = self.__utilities.get(interface)
         if c is None:
             c = default
         return c


=== Zope3/lib/python/Zope/ComponentArchitecture/GlobalViewService.py 1.4 => 1.5 ===
 $Id$
 """
 
-from IToIRegistry import IToIRegistry, IToIDataRegistry
+from Interface.Registry.AdapterRegistry import AdapterRegistry
 from Exceptions import ComponentLookupError
 from Zope.ComponentArchitecture import getSkin
 from IViewService import IViewService
@@ -44,48 +44,12 @@
 
     def __init__(self):
         self.__layers = {}
-        self.__default_view_names = IToIDataRegistry()
+        self.__default_view_names = AdapterRegistry()
 
     def setDefaultViewName(self, i_required, i_provided, name):
         self.__default_view_names.register(i_required,
                                            i_provided,
                                            name)
-        
-    # Implementation methods for interface
-    # Zope.ComponentArchitecture.IViewService.
-
-    def getViewDefinitions(self, name=None, used_for=None, type=None,
-                           layer=None):
-        '''See interface IViewService'''
-
-        result = []
-
-        if layer is None:
-            layers = self.__layers.keys()
-        else:
-            layers = [layer]
-
-        for layername in layers:
-            layer = self.__layers[layername]
-            if name is None:
-                names = layer.keys()
-            else:
-                names = [name]
-
-            for n in names:
-                result.extend(
-                    [{ 'name': n,
-                       'used_for': definition['used_for'],
-                       'type': definition['provides'],
-                       'layer': layername,
-                       'factory': definition['factory'],
-                       }
-                     for definition
-                     in layer[n].getDefinitions(used_for, type)
-                     ]
-                    )
-                    
-        return result                
 
     def getView(self, object, name, request):
         '''See interface IViewService'''
@@ -133,7 +97,16 @@
 
         reg = views.get(name, None)
         if reg is None:
-            reg = views[name] = IToIRegistry()
+            reg = views[name] = AdapterRegistry()
+
+        if not isinstance(maker, (list, tuple)):
+            maker = [maker]
+        else:
+            maker = list(maker)
+
+        if not maker == filter(callable, maker):
+            raise TypeError("The registered component callable is not "
+                            "callable")
 
         reg.register(forInterface, type, maker)
 


=== Zope3/lib/python/Zope/ComponentArchitecture/IPlacefulComponentArchitecture.py 1.3 => 1.4 ===
         
         """
 
-    def getViewDefinitions(context, name=None, used_for=None, \
-                           view_type=None, layer=None):
-        """Get matching view definitions for the given context.  If the
-        context is None then it will explicitly use the global view
-        service.
-
-        Get view definitions as a sequence of mapping objects with keys:
-
-        - name
-
-        - used_for
-
-        - type
-
-        - layer
-
-        - factory
-
-        The arguments may be given as keyword arguments and define a
-        query for the retrieval.
-        """
-
     # Resource service
 
     def getResource(wrapped_object, name, request):


=== Zope3/lib/python/Zope/ComponentArchitecture/IViewService.py 1.2 => 1.3 ===
         The default will be returned if a suitable
         default view name for the object cannot be found.
         """
-
-    def getViewDefinitions(name=None, use_for=None, type=None, layer=None):
-        """Get matching view definitions
-
-        Get view definitions as a sequence of mapping objects with keys:
-
-        - name
-
-        - used_for
-
-        - type
-
-        - layer
-
-        - factory
-
-        The arguments may be given as keyword arguments and define a
-        query for the retrieval.
-        """


=== Zope3/lib/python/Zope/ComponentArchitecture/__init__.py 1.6 => 1.7 ===
                       'Views').queryDefaultViewName(wrapped_object,
                                                     request, default)
 
-def getViewDefinitions(context, name=None, used_for=None, 
-                       view_type=None, layer=None):
-    return getService(context, 'Views').getViewDefinitions(context,
-                                                           name, used_for,
-                                                           view_type, layer)
-
 # Resource service
 
 def getResource(wrapped_object, name, request):

=== Removed File Zope3/lib/python/Zope/ComponentArchitecture/IToIRegistry.py ===