[Zope-dev] Re: Acquisition (was: [Zope-dev] Overriding a method in an instance.)

Shane Hathaway shane@digicool.com
Mon, 10 Jul 2000 13:14:17 -0400


Steve Alexander wrote:
> 
> Shane Hathaway wrote:
> >
> > So it's mostly right-to-left, but sometimes left-to-right, and
> > sometimes in a less than predictable order.  I have an external method
> > that makes it clearer, if you're interested.
> 
> Yes please!

This method, instead of showing the acquisition algebra, shows the
actual graph of acquisition wrappers.  It's ordered in such a way that
you can search it from top to bottom to figure out exactly the behavior
of Acquisition.c.

Install this as an external method "showaq" at the base of your Zope
installation.  Then try different acquisition paths:

http://localhost:8080/QuickStart/showaq
http://localhost:8080/QuickStart/Outline/QuickStart/showaq
http://localhost:9080/QuickStart/Outline/QuickStart/Control_Panel/showaq

A vertical line refers to aq_parent, which is a "context" link.  A
diagonal line refers to aq_self, which is a "containment" link. 
Containment never changes; it refers to the physical location of an
object.  Context, on the other hand, can be modified easily just by
changing the URL.

Some objects are in parentheses because they are not actually
searched.  But you'll notice that objects in parentheses have both an
aq_self and an aq_parent which refer to the same object.  I suppose
this method could be cleaned up to eliminate the redundancy, but my
goal was to see the actual structure of the wrappers.

So, without further ado, here is the method.

def showaq(self, indent=''):
    rval = ""
    obj = self
    base = getattr(obj, 'aq_base', obj)
    try: id = base.id
    except: id = str(base)
    try: id = id()
    except: pass
 
    if hasattr(obj, 'aq_self'):
        if hasattr(obj.aq_self, 'aq_self'):
            rval = rval + indent + "(" + id + ")\n"
            rval = rval + indent + "|  \\\n"
            rval = rval + showaq(obj.aq_self, '|   ' + indent)
            rval = rval + indent + "|\n"
        if hasattr(obj, 'aq_parent'):
            rval = rval + indent + id + "\n"
            rval = rval + indent + "|\n"
            rval = rval + showaq(obj.aq_parent, indent)
    else:
        rval = rval + indent + id + "\n"
    return rval



Shane

P.S. I wouldn't mind if someone posted this as a HOWTO. :-)