Dieter Maurer wrote:
> Martin Aspeli wrote at 2007-1-6 22:22 +0000:
>> ....
>>  - Registering the portal as a utility that can be obtained by 
>> getUtility(IPortalRoot) is pretty good practice; in my estimation, that 
>> should solve all the use cases for utilities where acquisition is used 
>> now and where we're not really after an adapter, view.
> But the returned object is almost worthless, if it is not
> acquistion wrapped (otherwise, it is not even able to determine its
> 'getPhysicalPath' or 'absolute_url').
> Thus, the proposal exhibits an essential example that local
> utilities should be returned acquisition wrapped (if the have an '__of__'
> method).

Maybe a compromise would be to only return those utilities back
acquisition wrapped that where registered as tools?

Jens added a new function to CMFCore.utils called registerToolInterface
that registers a tools name and the interface that tool implements in a
global registry (a simple module level dict). The primary purpose is to
let getToolByName look up known tools by interface instead of using

While I'm not too proud of my persistent component registry proposed
earlier in this thread it could be extended easily to only return those
utilities back AQ-wrapped that are registered in the global tools registry.

See my attached file for a sample implementation.

Personally I think AQ-wrapping every utility is a bit too much as well.
I've written a number of new utilities for Plone 3.0 that while having
some persistent configuration don't need any Acquisition context.
Magically wrapping those might indeed lead to unexpected behavior.

from zope.component.persistentregistry import PersistentComponents
from Acquisition import aq_parent, Explicit

from Products.CMFCore.utils import _tool_interface_registry

class Zope2PersistentComponents(Explicit, PersistentComponents):

    def queryUtility(self, provided, name=u'', default=None):
        utilities = super(Zope2PersistentComponents, 
self).queryUtility(provided, name=name, default=default)
        if utilities is not None:
            # Only wrap those utilities that are also cmf tools
            if provided in _tool_interface_registry.values() and \
               getattr(utilities, '__of__', None) is not None:
                return utilities.__of__(aq_parent(self))
        return utilities

    def getUtility(self, provided, name=u''):
        utility = super(Zope2PersistentComponents, self).getUtility(provided, 
        # Only wrap those utilities that are also cmf tools
        if provided in _tool_interface_registry.values() and \
           getattr(utility, '__of__', None) is not None:
            return utility.__of__(aq_parent(self))
        return utility
Zope-CMF maillist  -

See for bug reports and feature requests

Reply via email to