[Zope3-checkins] CVS: Zope3/src/zope/app/browser/services - cache.py:1.14 connection.py:1.18 menu.py:1.4

Stephan Richter srichter at cosmos.phy.tufts.edu
Tue Aug 19 20:11:31 EDT 2003


Update of /cvs-repository/Zope3/src/zope/app/browser/services
In directory cvs.zope.org:/tmp/cvs-serv7817/browser/services

Modified Files:
	cache.py connection.py menu.py 
Log Message:
Cleaned up the recent code significantly now that I understand the local
utility service better. Using registeredMatching() was just not the right
method to use. 

Added a new method called getLocalUtitliesFor() so that it is easier to 
grab the locally defined utilities only.


=== Zope3/src/zope/app/browser/services/cache.py 1.13 => 1.14 ===
--- Zope3/src/zope/app/browser/services/cache.py:1.13	Tue Aug 19 13:34:02 2003
+++ Zope3/src/zope/app/browser/services/cache.py	Tue Aug 19 19:10:55 2003
@@ -28,29 +28,21 @@
     def getLocalCaches(self):
         caches = []
         utilities = zapi.getService(self.context, Utilities)
-        matching = utilities.getRegisteredMatching(ICache)
-        for match in matching:
-            caches.append(self.buildInfo(match))
+        for id, cache in utilities.getLocalUtilitiesFor(ICache):
+            caches.append(self.buildInfo(id, cache))
         return caches
 
-
     def getInheritedCaches(self):
         caches = []
-        next = queryNextService(self.context, Utilities)
-        while next is not None:
-            matching = next.getRegisteredMatching(ICache)
-            for match in matching:
-                caches.append(self.buildInfo(match))
-            next = queryNextService(next, Utilities)
+        utilities = queryNextService(self.context, Utilities)
+        for id, cache in utilities.getUtilitiesFor(ICache):
+            caches.append(self.buildInfo(id, cache))
         return caches
 
-
-    def buildInfo(self, match):
+    def buildInfo(self, id, cache):
         info = {}
-        info['id'] = match[1]
-        info['url'] = str(zapi.getView(match[2].active().getComponent(),
-                                       'absolute_url', self.request))
-
+        info['id'] = id
+        info['url'] = str(zapi.getView(cache, 'absolute_url', self.request))
         return info
 
 
@@ -60,6 +52,8 @@
 
     def add(self, content):
         if not ICache.isImplementedBy(content):
-            raise TypeError("%s is not a Cache" % content)
+            error = _("${object} is not a Cache.")
+            error.mapping['object'] = str(content)
+            raise TypeError(error)
 
         return zapi.ContextSuper(CacheAdding, self).add(content)


=== Zope3/src/zope/app/browser/services/connection.py 1.17 => 1.18 ===
--- Zope3/src/zope/app/browser/services/connection.py:1.17	Tue Aug 19 13:34:02 2003
+++ Zope3/src/zope/app/browser/services/connection.py	Tue Aug 19 19:10:55 2003
@@ -28,30 +28,22 @@
     def getLocalConnections(self):
         conns = []
         utilities = zapi.getService(self.context, Utilities)
-        matching = utilities.getRegisteredMatching(IZopeDatabaseAdapter)
-        for match in matching:
-            conns.append(self.buildInfo(match))
+        for id, conn in utilities.getLocalUtilitiesFor(IZopeDatabaseAdapter):
+            conns.append(self.buildInfo(id, conn))
         return conns
 
-
     def getInheritedConnections(self):
         conns = []
-        next = queryNextService(self.context, Utilities)
-        while next is not None:
-            matching = next.getRegisteredMatching(IZopeDatabaseAdapter)
-            for match in matching:
-                conns.append(self.buildInfo(match))
-            next = queryNextService(next, Utilities)
+        utilities = queryNextService(self.context, Utilities)
+        for id, conn in utilities.getUtilitiesFor(IZopeDatabaseAdapter):
+            conns.append(self.buildInfo(id, conn))
         return conns
 
-
-    def buildInfo(self, match):
+    def buildInfo(self, id, conn):
         info = {}
-        info['id'] = match[1]
-        info['url'] = str(zapi.getView(match[2].active().getComponent(),
-                                       'absolute_url', self.request))
-
-        info['dsn'] = match[2].active().getComponent().dsn    
+        info['id'] = id
+        info['url'] = str(zapi.getView(conn, 'absolute_url', self.request))
+        info['dsn'] = conn.dsn
         return info
 
 
@@ -61,6 +53,7 @@
 
     def add(self, content):
         if not IZopeDatabaseAdapter.isImplementedBy(content):
-            raise TypeError("%s is not a zope database adapter" % content)
+            error = _("${object} is not a Zope database adapter.")
+            error.mapping['object'] = str(content)
 
         return zapi.ContextSuper(ConnectionAdding, self).add(content)


=== Zope3/src/zope/app/browser/services/menu.py 1.3 => 1.4 ===
--- Zope3/src/zope/app/browser/services/menu.py:1.3	Sun Aug 17 02:05:47 2003
+++ Zope3/src/zope/app/browser/services/menu.py	Tue Aug 19 19:10:55 2003
@@ -21,7 +21,7 @@
 from zope.app.component.nextservice import queryNextService
 from zope.app.interfaces.dublincore import IZopeDublinCore
 from zope.app.interfaces.services.menu import ILocalBrowserMenu
-from zope.app.services.servicenames import Utilities
+from zope.app.services.servicenames import Utilities, BrowserMenu
 from zope.security.proxy import trustedRemoveSecurityProxy
 
 class MenuContents(Contents):
@@ -56,30 +56,21 @@
     def getLocalMenus(self):
         menus_info = []
         utilities = zapi.getService(self.context, Utilities)
-        matching = utilities.getRegisteredMatching(ILocalBrowserMenu)
-        matching = map(lambda m: (m[1], m[2].active().getComponent()),
-                       matching)
-        for menu_id, menu in matching:
+        for menu_id, menu in utilities.getLocalUtilitiesFor(ILocalBrowserMenu):
             menus_info.append(self._getInfoFromMenu(menu_id, menu))
         return menus_info
 
 
     def getInheritedMenus(self):
-        next = queryNextService(self.context, "BrowserMenu")
         menus = []
-        while next is not None:
-            try:
-                menus += next.items()
-            except AttributeError:
-                # We deal with a global browser menu service
-                service = trustedRemoveSecurityProxy(next)
-                menus += service._registry.items()
-            next = queryNextService(next, "BrowserMenu")
-    
-        menus_info = []
-        for menu_id, menu in menus:
-            menus_info.append(self._getInfoFromMenu(menu_id, menu))
-        return menus_info
+        utilities = queryNextService(self.context, Utilities)
+        for id, menu in utilities.getUtilitiesFor(ILocalBrowserMenu):
+            menus.append(self._getInfoFromMenu(id, menu))
+        # Global Browser Menus
+        service = zapi.getService(None, BrowserMenu)
+        for id, menu in service._registry.items():
+            menus.append(self._getInfoFromMenu(id, menu))
+        return menus
             
 
     def _getInfoFromMenu(self, menu_id, menu):
@@ -90,7 +81,7 @@
         info['inherit'] = False
         if getattr(menu, 'inherit', False):
             info['inherit'] = True
-            next = queryNextService(menu, "BrowserMenu")
+            next = queryNextService(menu, BrowserMenu)
             if next is not None:
                 try:
                     inherit_menu = next.queryLocalMenu(menu_id)




More information about the Zope3-Checkins mailing list