[Zope-CMF] Re: [CMF 2.1] FSPageTemplate & Unicode

Hanno Schlichting plone at hannosch.info
Sat Jan 6 16:53:32 EST 2007


Jens Vagelpohl wrote:
> 
> Now, the main issue is still there, how to deal with tool wrapping when
> calling getUtility/queryUtility in trusted code. Doing it every time
> right after the call is stupid. I like Tres' hardline assertion that we
> must have it wrapped every time, automatically. This needs to be
> implemented somehow, maybe in Five as he suggests.
> 
> How do we proceed?

Personally I like Tres idea as well. I had one idea so far that achieves
this without monkey-patching the functions in zope.component.

The idea is to use a specialized persistent component registry, that
does the needed AQ-wrapping.

This will however only give us AQ-wrapped local utilities, whereas those
registered with the global component registry wouldn't be wrapped. I
think this might be an acceptable trade-off.

Instead of creating a PersistentComponents registry in setuphandlers.py
in CMFDefault (or CMFPlone) we could use the following one:


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


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:
            if 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, name=name)
        if getattr(utility, '__of__', None) is not None:
            return utility.__of__(aq_parent(self))
        return utility


I'm not sure about all the implications this has, so treat it with care
;) Also we would probably need to overwrite all the other methods that
return utilities like getUtilitiesFor, registeredUtilities, ... and we
would need to make a decision about how to handle adapters or subscribers.

Thoughts?

Hanno



More information about the Zope-CMF mailing list