[Zope3-checkins] SVN: Zope3/trunk/src/zope/ Changed getUtilitiesFor to be consistent with recent

Jim Fulton jim at zope.com
Sat May 22 13:30:09 EDT 2004


Log message for revision 24883:
Changed getUtilitiesFor to be consistent with recent
component-architecture changes.




-=-
Modified: Zope3/trunk/src/zope/app/apidoc/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/apidoc/__init__.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/apidoc/__init__.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -61,7 +61,7 @@
 
     def items(self):
         """See zope.app.container.interfaces.IReadContainer"""
-        items = list(zapi.getUtilitiesFor(self, IDocumentationModule))
+        items = list(zapi.getUtilitiesFor(IDocumentationModule))
         items.sort()
         utils = []
         for key, value in items:

Modified: Zope3/trunk/src/zope/app/applicationcontrol/browser/translationdomaincontrol.py
===================================================================
--- Zope3/trunk/src/zope/app/applicationcontrol/browser/translationdomaincontrol.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/applicationcontrol/browser/translationdomaincontrol.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -23,7 +23,7 @@
 
     def getCatalogsInfo(self):
         info = []
-        for name, domain in zapi.getUtilitiesFor(None, ITranslationDomain):
+        for name, domain in zapi.getUtilitiesFor(ITranslationDomain):
             if not hasattr(domain, 'getCatalogsInfo'):
                 continue
             for language, fileNames in domain.getCatalogsInfo().items():

Modified: Zope3/trunk/src/zope/app/cache/interfaces/__init__.py
===================================================================
--- Zope3/trunk/src/zope/app/cache/interfaces/__init__.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/cache/interfaces/__init__.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -28,8 +28,7 @@
     def __allowed(self):
         """Note that this method works only if the Field is context wrapped.
         """
-        names = [name \
-                 for name, util in zapi.getUtilitiesFor(self.context, ICache)]
+        names = [name for name, util in zapi.getUtilitiesFor(ICache)]
         return names + ['']
 
     allowed_values = property(__allowed)

Modified: Zope3/trunk/src/zope/app/cache/tests/test_cachename.py
===================================================================
--- Zope3/trunk/src/zope/app/cache/tests/test_cachename.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/cache/tests/test_cachename.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -25,6 +25,7 @@
 from zope.app.site.tests.placefulsetup import PlacefulSetup
 from zope.app.annotation.interfaces import IAttributeAnnotatable
 from zope.app.utility import LocalUtilityService
+from zope.thread import thread_globals
 
 class CacheStub(object):
     __name__ = __parent__ = None
@@ -38,11 +39,17 @@
     def setUp(self):
         PlacefulSetup.setUp(self, folders=True)
         sm = self.makeSite()
+        thread_globals().site = sm.__parent__
+        
         setup.addService(sm, 'Utilities', LocalUtilityService())
         setup.addUtility(sm, 'bar', ICache, CacheStub())
         setup.addUtility(sm, 'baz', ICache, CacheStub())
         setup.addUtility(sm, 'foo', ICache, CacheStub())
 
+    def tearDown(self):
+        PlacefulSetup.tearDown(self)
+        thread_globals().site = None
+
     def test(self):
         field = CacheName().bind(self.rootFolder)
         allowed = list(field.allowed_values)

Modified: Zope3/trunk/src/zope/app/dav/propfind.py
===================================================================
--- Zope3/trunk/src/zope/app/dav/propfind.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/dav/propfind.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -80,7 +80,7 @@
         # XXX For now, list the propnames for the all namespaces
         # but later on, we need to list *all* propnames from *all* known
         # namespaces that this object has.
-        for ns, iface in zapi.getUtilitiesFor(None, IDAVNamespace):
+        for ns, iface in zapi.getUtilitiesFor(IDAVNamespace):
             _avail_props[ns] = getFieldNamesInOrder(iface)
         propname = xmldoc.getElementsByTagNameNS(self.default_ns, 'propname')
         if propname:

Modified: Zope3/trunk/src/zope/app/generations/browser/managers.py
===================================================================
--- Zope3/trunk/src/zope/app/generations/browser/managers.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/generations/browser/managers.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -155,7 +155,7 @@
            """
 
         self.managers = managers = dict(
-            zapi.getUtilitiesFor(None, ISchemaManager))
+            zapi.getUtilitiesFor(ISchemaManager))
         db = self._getdb()
         conn = db.open()
         try:

Modified: Zope3/trunk/src/zope/app/generations/generations.py
===================================================================
--- Zope3/trunk/src/zope/app/generations/generations.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/generations/generations.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -105,7 +105,7 @@
 def findManagers():
     # Hook to let Chris use this for Zope 2
     import zope.app
-    return zope.app.zapi.getUtilitiesFor(None, ISchemaManager)
+    return zope.app.zapi.getUtilitiesFor(ISchemaManager)
 
 def PersistentDict():
     # Another hook to let Chris use this for Zope 2

Modified: Zope3/trunk/src/zope/app/rdb/tests/test_directives.py
===================================================================
--- Zope3/trunk/src/zope/app/rdb/tests/test_directives.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/rdb/tests/test_directives.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -29,7 +29,7 @@
 
     def test_provideConnection(self):
 
-        conns = list(zapi.getUtilitiesFor(None, IZopeDatabaseAdapter))
+        conns = list(zapi.getUtilitiesFor(IZopeDatabaseAdapter))
         self.assertEqual(conns, [])
         connectionstub = queryUtility(IZopeDatabaseAdapter, None, 'stub')
         self.assertEqual(connectionstub, None)
@@ -38,7 +38,7 @@
         connectionstub = queryUtility(IZopeDatabaseAdapter, None, 'stub')
         connection = connectionstub()
         self.assertEqual(connectionstub.__class__, DAStub)
-        conns = zapi.getUtilitiesFor(None, IZopeDatabaseAdapter)
+        conns = zapi.getUtilitiesFor(IZopeDatabaseAdapter)
            
         self.assertEqual([c[0] for c in conns], ["stub"])
         self.assertEqual(connection.__class__, ZopeConnection)

Modified: Zope3/trunk/src/zope/app/security/permission.py
===================================================================
--- Zope3/trunk/src/zope/app/security/permission.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/security/permission.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -53,7 +53,7 @@
     if not zapi.queryUtility(IPermission, name=permission_id, context=context):
         raise ValueError("Undefined permission id", permission_id)
 
-def allPermissions(context):
+def allPermissions(context=None):
     """Get the ids of all defined permissions
 
     >>> from zope.app.tests.placelesssetup import setUp, tearDown
@@ -70,6 +70,6 @@
 
     >>> tearDown()
     """
-    for id, permission in zapi.getUtilitiesFor(context, IPermission):
+    for id, permission in zapi.getUtilitiesFor(IPermission, context):
         if id != u'zope.Public':
             yield id

Modified: Zope3/trunk/src/zope/app/securitypolicy/browser/principalpermissionview.py
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/principalpermissionview.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/principalpermissionview.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -81,7 +81,7 @@
         ppmap = IPrincipalPermissionMap(self.context)
         principal = self.get_principal(principal_id)
         result = []
-        for perm in zapi.getUtilitiesFor(self.context, IPermission):
+        for perm in zapi.getUtilitiesFor(IPermission):
             if ppmap.getSetting(perm, principal) == Unset:
                 result.append(perm)
 

Modified: Zope3/trunk/src/zope/app/securitypolicy/browser/principalroleview.py
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/principalroleview.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/principalroleview.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -42,7 +42,7 @@
         if roles is None:
             roles = self._roles = \
               [role
-               for name, role in zapi.getUtilitiesFor(self.context, IRole)]
+               for name, role in zapi.getUtilitiesFor(IRole)]
         return roles
 
     def createGrid(self, principals=None, roles=None):
@@ -63,7 +63,7 @@
                 roles = self.getAllRoles()
             else:
                 # XXX This code path needs a test
-                utils = zapi.getUtilitiesFor(self.context, IRole)
+                utils = zapi.getUtilitiesFor(IRole)
                 roles = [role for name, role in utils if name in roles]
 
         return PrincipalRoleGrid(principals, roles, self.context)

Modified: Zope3/trunk/src/zope/app/securitypolicy/browser/rolepermissionview.py
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/browser/rolepermissionview.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/securitypolicy/browser/rolepermissionview.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -32,15 +32,14 @@
         roles = getattr(self, '_roles', None)
         if roles is None:
             roles = self._roles = \
-              [role for name, role in zapi.getUtilitiesFor(self.context, IRole)]
+              [role for name, role in zapi.getUtilitiesFor(IRole)]
         return roles
 
     def permissions(self):
         permissions = getattr(self, '_permissions', None)
         if permissions is None:
             permissions = self._permissions = \
-              [perm for name, perm in zapi.getUtilitiesFor(self.context,
-                                                           IPermission)]
+              [perm for name, perm in zapi.getUtilitiesFor(IPermission)]
         return permissions
 
     def availableSettings(self, noacquire=False):

Modified: Zope3/trunk/src/zope/app/securitypolicy/role.py
===================================================================
--- Zope3/trunk/src/zope/app/securitypolicy/role.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/securitypolicy/role.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -58,6 +58,6 @@
     
 
 def checkRole(context, role_id):
-    names = [name for name, util in zapi.getUtilitiesFor(context, IRole)]
+    names = [name for name, util in zapi.getUtilitiesFor(IRole, context)]
     if not role_id in names:
         raise ValueError("Undefined role id", role_id)

Modified: Zope3/trunk/src/zope/app/site/browser/tools.py
===================================================================
--- Zope3/trunk/src/zope/app/site/browser/tools.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/site/browser/tools.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -71,7 +71,7 @@
 class ToolsOverview:
     def getTools(self):
         tools = []
-        for n, iface in zapi.getUtilitiesFor(None, IToolType):
+        for n, iface in zapi.getUtilitiesFor(IToolType):
             name = iface.getName()
             view = zapi.getView(self.context, 'manage%sTool.html' % name,
                                 self.request)

Modified: Zope3/trunk/src/zope/app/utility/vocabulary.py
===================================================================
--- Zope3/trunk/src/zope/app/utility/vocabulary.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/utility/vocabulary.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -201,7 +201,7 @@
             nameOnly = True
         if isinstance(interface, (str, unicode)):
             interface = zapi.getUtility(IInterface, interface)
-        utils = zapi.getUtilitiesFor(context, interface)
+        utils = zapi.getUtilitiesFor(interface, context)
         self._terms = dict([(name, UtilityTerm(nameOnly and name or util, name))
                             for name, util in utils])
 

Modified: Zope3/trunk/src/zope/app/workflow/stateful/browser/contentworkflow.py
===================================================================
--- Zope3/trunk/src/zope/app/workflow/stateful/browser/contentworkflow.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/app/workflow/stateful/browser/contentworkflow.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -65,8 +65,9 @@
     def getProcessInterfacesMapping(self):
         mapping = []
         for name in [name for name, util in zapi.getUtilitiesFor(
+                                                       IProcessDefinition,
                                                        self.context,
-                                                       IProcessDefinition)]:
+                                                       )]:
             ifaces = self.context.getInterfacesForProcessName(name)
             ifaces = map(lambda i: interfaceToName(self.context, i), ifaces)
             if ifaces:

Modified: Zope3/trunk/src/zope/component/__init__.py
===================================================================
--- Zope3/trunk/src/zope/component/__init__.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/component/__init__.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -124,8 +124,12 @@
     return getService(Utilities, context).queryUtility(
         interface, default, name)
 
-def getUtilitiesFor(context, interface):
-    return getService(context, Utilities).getUtilitiesFor(interface)
+def getUtilitiesFor(interface, context=None):
+    if not IInterface.providedBy(interface):
+        raise TypeError("getUtilitiesFor got nonsense arguments."
+                        " Check that you are updated with the"
+                        " component API change.")
+    return getService(Utilities, context).getUtilitiesFor(interface)
 
 # Adapter service
 

Modified: Zope3/trunk/src/zope/component/interfaces.py
===================================================================
--- Zope3/trunk/src/zope/component/interfaces.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/component/interfaces.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -86,7 +86,7 @@
         the specified interface.  If one is not found, returns default.
         """
 
-    def getUtilitiesFor(context, interface):
+    def getUtilitiesFor(interface, context=None):
         """Return the utilities that provide an interface
 
         An iterable of utility name-value pairs is returned.

Modified: Zope3/trunk/src/zope/component/tests/test_utilityservice.py
===================================================================
--- Zope3/trunk/src/zope/component/tests/test_utilityservice.py	2004-05-22 16:17:24 UTC (rev 24882)
+++ Zope3/trunk/src/zope/component/tests/test_utilityservice.py	2004-05-22 17:30:08 UTC (rev 24883)
@@ -71,7 +71,7 @@
     def testgetUtilitiesFor(self):
         us = getService(None, Utilities)
         us.provideUtility(IDummyUtility, dummyUtility)
-        self.assertEqual(list(getUtilitiesFor(None, IDummyUtility)),
+        self.assertEqual(list(getUtilitiesFor(IDummyUtility)),
                          [('',dummyUtility)])
         self.assertEqual(list(us.getUtilitiesFor(IDummyUtility)),
                          [('',dummyUtility)])




More information about the Zope3-Checkins mailing list