[Zope-dev] Philosophy.__of__(Acquisition).questions

Evan Simpson evan@4-am.com
Sun, 26 Sep 1999 15:28:07 -0500


I thought I understood Acquisition, until I read the docs at
http://www.digicool.com/releases/ExtensionClass/Acquisition.html.

*Really* read them, until my brain hurt, then I went and had a lie down,
then tried again.

Now I'm *really* confused!  Let me take the example from the docs:

We have a tree that includes paths a/x and a/b/c.  Whenever we ask an
object which supports acquisition for an attribute which turns out to
support acquisition, we are given a wrapper which preserves the
context.  Using 'of' to mean 'in the context of', the general
transformation rule is (path/top/attr) -> (path/attr) of (path/top) if
attr is not an element of top, or (path/attr) -> (attr of path) if it
is.

Here are some access paths and the resulting wrapper objects:

a/b
    b of a
a/b/c
    c of (a/b) -> c of (b of a)
a/x
    x of a
a/b/x
    (a/x) of (a/b) ->  (x of a) of (b of a)
a/b/c/x
    (a/b/x) of (a/b/c) -> ((a/x) of (a/b)) of (a/b/c) -> ((x of a) of (b
of a)) of (c of (b of a))

Once a wrapper is written in 'of' notation, you can read off the
acquisition order from left to right, skipping repeats.  Thus, for
'a/b/c', the acquisition order is c, b , a, while for 'a/b/c/x' it is x,
a, b, c.

The addition of x reverses the acquisition sequence for the previous
step!  If x were contained in b instead, then we would have a/b/c/x ->
(a/b/x) of (a/b/c) -> (x of b of a) of (c of b of a), giving sequence x,
b, a, c!!

This seemed horribly unintuitive to me, since I thought that an acquired
object was only given the context of the object which started the
acquisition search.  This would lead to the same result for 'a/b/c', but
'a/b/c/x' would give x, c, b, a.

Jim Fulton kindly explained, in another thread, how the acquired
object's context is searched before the acquiring object's.  Fine,
that's fully consistent with all of the above.

Now I try it out in Zope.  I make nested folders 'a/b/c' in the root.  I
put DTML method 'x' in 'a', and have it display <dtml-var prop>.  I give
a, b, and c properties named 'prop', containing 'a!', 'b!', and 'c!'
respectively.

I call '/a/b/c/x' and it prints 'c!'

What the hell?  According to the docs, shouldn't it print 'a!'?

Ok, let's try making DTML Method y in c with body "<dtml-var x>".  Same
result.  How about "<dtml-with x><dtml-var prop></dtml-with>"?  Same
thing.

Help??