[Zope] Changing Contexts (Was: [Zope] Acquisition? Did I just lose my Zen?)

Toby Dickenson htrd90@zepler.org
Thu, 30 Sep 1999 02:29:43 +0100


On Wed, 22 Sep 1999 18:52:39 -0300, you wrote:

>> Paulo Eduardo Neves wrote:
>> >
>> > "Jay R. Ashworth" wrote:
>> > >
>> > > Got it.  Then, I agree with the other folks.  How can you override the
>> > > context of the place where you acquired it _from_ with the context of
>> > > the place where you acquired it _to_?  That would seem to be a very
>> > > important ability...

I had been working with Zope for six months before realising that
acquisition did not work that way already, and I was relieved. Maybe I
can persuade you that it would be a bad thing.....

With the rules as they are, an object can always rely on acquisition
to source its containers first. Think of an object's containers as
part of it's implementation, and the rules feel right.

Under the rules suggested by Martjin, acquisition would source
attributes from an object's customers in preference to its containers
(As Jay wrote, the place where you acquired it _to_, rather than the
place where you acquired it _from_). I don't think you could use that
kind of acquistion to build a robust application, because of the
unbounded number of potential clients each object might encounter. An
object could never really rely on what it might pick up through
acquisition.

If you need that kind of wild flexibility then IMO it is better to
explicitly pass it from the client object as a parameter, rather than
asking it to be acquired from the client.


With the current rules it is almost possible to use acquistion in the
way that Martjin wanted, by ensuring that there is no object with the
right id in the acquiring object's containers; the acquisition search
can 'spill out' into other contexts. However this is dangerous for a
different reason; the search order may be diffent to what you
expect......

For those who think they understand it, heres a quick quiz. The script
below is a variation of one in the acquisition documention, but what
order are objects searched when looking up 'attribute' in these two
cases?

The answer is at the bottom of this email.

from Acquisition import Implicit

class C(Implicit):
    pass

root=C()
root.a=C()
root.a.b=C()
root.a.b.c=C()
root.x=C()
root.x.y=C()
root.x.y.z=C()

print root.a.b.c.attribute
print root.a.b.c.x.y.z.attribute




































'attribute' is looked up in the orders c-b-a-root and z-y-x-root-a-b-c

strange but true,


Toby Dickenson