Acquisiton Madness

Acquisition is a powerful concept which boils down to 'environmental inheritance' or objects retrieving attributes from their environment.

Even if you never use Acquisition explicitly in your own Products or depend on it in your Site, having a working understanding of what it does will help you understand what zope itself does.

Zope uses acquisition extensively and its security system is intimately tied to it. Also knowledge of acquisition can help you refactor your code to take advantage of this powerful Zope feature.

Terminology

Foundational Documentation

The all Important Madness and Confusion Thread

Visually Understanding Acquisition

Some Usage Documentation

Lets Play A Game

I'm attaching a brief session i conducted to explore acquisition.

i've defined two methods ahead of time, one is the showaq method referenced above (visual aquisition), and the other is a wrapper for it that looks like:

        def paq(obj): 
            print showaw(obj, '   ')

so lets play a game:

        cd /opt/zope/lib/python

        python

        >> from Acquisition import Implicit

        >> class C(Implicit):
              def __init__(self, name):
                  self.name = name
              def __repr__(self): return self.name

        >> # get some players

        >> a = C('a')
        >> b = C('b')
        >> c = C('c')
        >> d = C('d')
        >> e = C('e')

        >> # roll dice

        >> a.i = 0
        >> b.i = 2
        >> d.color = 'blue'
        >> c.color = 'red'

        >> # shuffle the deck and deal out cards

        >> a.b = b
        >> a.b.e = e
        >> a.c = c
        >> a.c.d = d

        >> # play ball

        >> print a.i
        0
        >> paq(a)

           a

        >> print a.b.i
        0

        >> paq(b)

           b
           |
           a

        >> print a.c.i
        0

        >> paq(a.c)

           c
           |
           a

        >> print a.c.d.i
        0

        >> paq(a.c.d)

           d
           | 
           c
           |
           A

        >> print a.c.b.i
        2

        >> paq(a.c.b)

           (b)
           |  \
        |      b
        |      |
        |      a
           |
           b
           |
           c
           |
           a

        >> print a.b.c.i
        0
        >> print a.c.b.d.i
        0

           d
           |
           (c)
           |  \
        |      c
        |      |
        |      a
           |
           c
           |
           b
           |
           a

        >> print a.b.c.d.e.i
        2

        >> print a.b.c.d.e.color
        'blue'

        >> paq(a.b.c.d.e)

           (e)
           |  \
        |      (e)
        |      |  \
        |   |      e
        |   |      |
        |   |      b
        |   |      |
        |   |      a
        |      |
        |      e
        |      |
        |      (c)
        |      |  \
        |   |      c
        |   |      |
        |   |      a
        |      |
        |      c
        |      |
        |      b
        |      |
        |      a
           |
           e
           |
           d
           |
           (c)
           |  \
        |      c
        |      |
        |      a
           |
           c
           |
           b
           |
           a

        >> # game over
        >> import sys;sys.exit()

What did we learn ~ Simple Rules

If you're containment matches your context, than things will behave as you expect.

If you're containment and context don't match, containment will get searched before context.

Author

Kapil Thangavelu

Thanks to Chris Withers for starting the acquisition madness thread

Thanks to Shane Hathaway for the very cool showaq method

Thanks to Evan Simpson for answering chris's questions and enlightening many.

ToDo

Add links to using acquisition from dtml (with/let)

Add links to escaping acquisition howtos