Steve Alexander wrote:
> 
> Here's an external method that ought to work. Well, it works for me:
> 
> # acquire the object of name "attr" by context alone
> def aquire_by_context(self, attr):
>     ob = self
>     while hasattr(ob, 'aq_base'):
>         aq_b=getattr(ob, 'aq_base', ob)
>         if hasattr(aq_b, attr):
>             attr_obj = getattr(aq_b, attr)
>             break;
>         ob = ob.aq_parent
>     else:
>         # not found
>         raise KeyError, attr
>     return self.restrictedTraverse(attr_obj.getPhysicalPath())

I'd left some cruft in there from debugging.

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
  

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

_______________________________________________
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )

Reply via email to