[Zope-dev] getPhysicalPath?
Brian Lloyd
brian@digicool.com
Fri, 16 Mar 2001 14:28:42 -0500
> To me, aswell. Is this documented somewhere? ;-)
It's not in the Acquisition.stx in the ExtensionClass docs -
probably they were never updated when it was added. I think
that aq_chain is most useful as a debugging aid rather than
something one would use in an application (which is not to
say that it shouldn't be documented). It would be a good idea
to add this to the Collector as a documentation issue.
> And can someone explain to us where the differences between
> aq_chain and getPhysicalPath() are? Actually getPhysicalPath()
> seems also to walk up aq_parent. Or am I missing something?
The sequence returned by aq_chain is the actual chain of
'acquisition contexts', or the 'access path' rather than
the actual containment path. For example, given the object
hierarchy:
app
FolderA
index_html
FolderB
If you say: ob = app.FolderA.FolderB.FolderA.index_html
then the aq_chain will be:
[index_html, FolderA, FolderB, FolderA, app]
This list is created by basically taking the 'aq_parent' of
each object from 'ob' on up until there are no more aq_parents.
The actual *containment* path is different; in our example
the containment path would be:
[index_html, FolderA, app]
To derive the containment path, instead of just walking up
the aq_parents you have to take the aq_inner (to get the
innermost wrapping of the object) for each object and then
take the aq_parent of that. For example (not tested, but
should work):
def containment_chain(object):
# return a list similar to aq_chain, but consisting
# only of the actual containment path.
result = []
result.append(object)
while hasattr(object, 'aq_inner'):
innermost_wrapping = object.aq_inner
true_parent = innermost_wrapping.aq_parent
result.append(true_parent)
object = true_parent
return result
Hope this helps!
Brian Lloyd brian@digicool.com
Software Engineer 540.371.6909
Digital Creations http://www.digicool.com