[z3-five] Plone Tool without acquisition

Philipp von Weitershausen philipp at weitershausen.de
Fri Feb 9 14:36:39 CET 2007


On 9 Feb 2007, at 14:26 , Chris Withers wrote:
> Philipp von Weitershausen wrote:
>>>> Why would you want to get hold of the site root? Assuming that  
>>>> the CMF tools are registered as local utilities, you should  
>>>> simply be able to say:
>>>>    from zope.component import getUtility
>>>>    from Products.CMFPlone.interfaces import IPloneTool # verify  
>>>> this
>>>>    plone_tool = getUtility(IPloneTool)
>>>> Zope will automatically figure out that where it should get that  
>>>> tool from (because it traversed over the site).
>>>
>>> Really? That feels a bit DWIM :-(
>> Yes.
>
> Do you see that as a good or a bad thing?

The yes was for the "really". If you don't believe me, read the  
chapter on Sites in my book. It's all explained in detail there.

IMO not having to specify a context is a good thing. Sometimes code  
doesnt' have access to a context, but it still wants to lookup a  
utility. Should it not be possible to let that utility come from a  
local component registry? I as the one who makes up application  
policy should be able to say where that utility comes from.

>>> I thought you had to pass in a context to get local utilities?
>> No. That's the point, the context is found during traversal and  
>> other code doesn't have to be aware of the context. In fact, why  
>> would code *care* where the utility is from? All it wants is a  
>> utility, be it local or global.
>
> Well, I'd imagine if you went to the trouble of registering local  
> utilities, you did so for a reason?

You're missing the point. The code that's looking up the utility  
might be some completely different piece of software than the piece  
of code that provides the utility. Where that utility is registered  
is an implementation detail of the utility in the end. The code  
looking up the utility just wants to get an ISomething, no matter  
where it's from.

> If that's the case, then how do I make sure the right utilities are  
> used when I'm traversing around several objects in different  
> locations in the same piece of code?

There's only one kind of traversal -- URL traversal -- and it only  
happens once per request. The other thing sometimes referred to as  
"traversal" is resolving object graphs. That doesnt' trigger the site  
remembering code.

> I guess I'm interested in what couldn't as "traversed over" and how  
> I can, if I need to, override where "Zope" thinks I've been  
> traversing...

I don't think there's anything to worry about.


More information about the z3-five mailing list