[Zope3-checkins] CVS: Zope3/src/zope/component - presentation.py:1.5 utility.py:1.7

Stephan Richter srichter at cosmos.phy.tufts.edu
Thu Jan 29 12:37:20 EST 2004


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

Modified Files:
	presentation.py utility.py 
Log Message:
Fixed a bug and added a test for UtilityService.getRegisteredMatching().

Reimplemented getRegisteredMatching() for the PresentationService. It is 
not part of the API yet, but we should do that!

As far as I can tell, the zope.component package is in a bad shape due to 
some refactorings. There are missing documentation strings everywhere and 
there are many legacy methods hanging around.


=== Zope3/src/zope/component/presentation.py 1.4 => 1.5 ===
--- Zope3/src/zope/component/presentation.py:1.4	Wed Dec 17 05:06:51 2003
+++ Zope3/src/zope/component/presentation.py	Thu Jan 29 12:36:49 2004
@@ -69,7 +69,7 @@
     """
 
 class GlobalPresentationService(GlobalService):
-    """Global presentation service
+    r"""Global presentation service
 
        The global presentation service provides management of views, and
        resources arranged in skins, where skins are ordered collections
@@ -195,6 +195,25 @@
        True
        >>> v.context is c
        True
+
+       Let's now test 'getRegisteredMatching()'. This function returns a
+       dictionary with the keys being the layers.
+       
+       >>> match = s.getRegisteredMatching(request=IRequest)
+       >>> match.keys()
+       ['custom']
+       >>> match['custom'][0] == \
+       ...     (IContact, ITraverse, (IRequest,), u'', [Traverser])
+       True
+
+       >>> match = s.getRegisteredMatching(IContact, IRequest)
+       >>> match['custom'][0] == \
+       ...     (IContact, ITraverse, (IRequest,), u'', [Traverser])
+       True
+
+       >>> s.getRegisteredMatching(request=IRequest, layers=['default']) == {}
+       True
+
        """
 
     zope.interface.implements(IPresentationService, IGlobalPresentationService)
@@ -400,6 +419,40 @@
                 return r
         return default
 
+
+    def getRegisteredMatching(self,
+                              object=None,
+                              request=None,
+                              name=None,
+                              providing=zope.interface.Interface,
+                              layers=None):
+        """Search for registered presentation components
+
+        'object' is usually an interface, but can also be a class, since one
+        can also create a view for a particular class/implementation.
+
+        'layers' is expected to be none or a list of existing layer names. If
+        you specified a layer that is not known, a 'KeyError' will be raised.
+
+        There is probably no need to ever change 'providing' to something
+        else.
+        """
+        assert request is not None
+        
+        results = {}
+        
+        if layers is None:
+            layers = self._layers.keys()
+
+        for layername in layers:
+            layer = self._layers[layername]
+            views = tuple(layer.getRegisteredMatching(object, providing,
+                                                      name, (request,)))
+            if views:
+                results[layername] = views
+                
+        return results
+
     ############################################################
     #
     # The following methods are provided for convenience and for
@@ -445,13 +498,6 @@
             factory = [factory]
         return self.provideAdapter(request_type, factory, name, layer=layer,
                                    providing=providing)
-
-    def getRegisteredMatching(self, layers=None, **kw):
-        if layers is None:
-            layers = self._layers.keys()
-            layers.sort()
-        for layername in layers:
-            layer = self._layers[layername]
 
 
 def GL(presentation_service, layer_name):


=== Zope3/src/zope/component/utility.py 1.6 => 1.7 ===
--- Zope3/src/zope/component/utility.py:1.6	Fri Aug 15 20:44:40 2003
+++ Zope3/src/zope/component/utility.py	Thu Jan 29 12:36:49 2004
@@ -74,7 +74,7 @@
         L = []
         for reg_name in self.__utilities:
             for iface, c in self.__utilities[reg_name].getRegisteredMatching():
-                if not c:
+                if c is None:
                     continue
                 if interface and not iface is interface:
                     continue
@@ -87,7 +87,7 @@
         utilities = {}
         for name in self.__utilities:
             for iface, util in self.__utilities[name].getRegisteredMatching():
-                if not util:
+                if util is None:
                     continue
                 if interface and not iface.extends(interface, 0) and \
                        util is not interface:




More information about the Zope3-Checkins mailing list