[Zope] finding out where a (property) value was acquired from
Dieter Maurer
dieter@handshake.de
Mon, 17 Sep 2001 20:46:03 +0200 (CEST)
Mitchell L Model writes:
> Is there something built-in to Zope that gives me the folder a value
> (or a property) was acquired from? Or do I simply have to walk the
> path back towards the root to find it?
No.
If the object you access is not a property (simple type)
but an AcquisitionWrapper, you can use "wrapper.aq_inner.aq_parent"
to locate the the containing object (works only in an
external method, as "aq_inner" is not considered safe (do not know why!)).
For objects of simple type, you would need to emulate the acquisition
lookup:
External method "findContainer":
def findContainer(obj,attr):
if hasattr(obj,'aq_self'):
c= findContainer(obj.aq_self,attr)
if c is None: return findContainer(obj.aq_parent,attr)
return c
if hasattr(obj,attr): return obj
return None
This will return either the containing object or None.
Dieter