[Zope] Acquisition crutch

Toby Dickenson tdickenson@geminidataloggers.com
Tue, 30 Nov 1999 18:13:38 -0000


Ive had some more problems which I thought might be due to unexpected
acquisition contexts, so I created this function as a diagnostic tool. I
_think_ it correctly displays the order in which objects are searched for
attributes.... Could anyone with acquisition Zen confirm it's doing the
right thing?

thanks,


def aq_order(ob):
    """Return a list of object repr's, showing the order in which
    the various objects in the acquisition tree will searched for
    attributes.
    """
    return _aq_order(ob,[])

def _aq_order(ob,old):
    if hasattr(ob,'aq_self'):
        # It's an acquisition wrapper
        return _aq_order(ob.aq_self,old) + _aq_order(ob.aq_parent,old)
    else:
        # Its a real object
        if ob in old:
            # This has already been looked up
            # return [ '(%s)' % repr(ob) ]
            return []
        else:
            old.append(ob)
            return [ repr(ob) ]