[Zope-dev] Re: Acquisition by context first

Steve Alexander steve@cat-box.net
Fri, 15 Sep 2000 13:13:34 +0100


Steve Alexander wrote:
> 
> Of course, you can simplify it to:
> 
> # acquire the object of name "attr" by context alone
> def aquire_by_context(self, attr):
>     ob = self
>     while hasattr(ob, 'aq_base'):
>         if hasattr(ob.aq_base, attr):
>             return self.restrictedTraverse(
>                     getattr(ob.aq_base, attr).getPhysicalPath())
>         ob = ob.aq_parent
> 
>     # not found
>     raise KeyError, attr

I should point out that this is just for finding an object by context
alone.
The context-only acquisition meme doesn't get passed on to anything that
the returned object might in turn call.

This makes this external method less useful than having a fancy
acquisition context that checks for security by containment whilst
getting attributes by context. However, such a fancy acquisition context
would be much more complex to design.

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net