[Zope] UNEXPECTED: Acquisition.Explicit may acquire implicitly

Dieter Maurer dieter@handshake.de
Sun, 31 Dec 2000 16:21:47 +0100


While trying to understand, what the "bself= self.aq_explicit"
in "OFS.DTMLMethod.__call__" should do, I detected an unexpected
behaviour:

    usually, this "bself" acquires implicitly from
    its container (though not from its context)

More precisely:

    if "bself.aq_self" is itself an implicit acquisition
    wrapper, the "bself.aq_explicit" acquires implicitly
    from "bself.aq_self.aq_parent".

The following Python module demonstrates the behaviour:

-------------------------------------------------------
from Acquisition import Implicit

class C(Implicit): pass

b= C()
b.i= 0
b.d= C()
b.h= C()

e_bd= b.d.aq_explicit
try:
    e_bd.i 
    print 'e_bd implicitly acquired i'
except AttributeError: pass

e_bhd= b.h.d.aq_explicit
try:
    e_bhd.i 
    print 'e_bhd implicitly acquired i'
except AttributeError: pass
-------------------------------------------------------


At first, I thought this were a bug.
At second thought, however, it appears to be quite
natural, though unexpected:

    if o is self.__of__(parent), then
    getattr(o.aq_explicit,k) = getattr(self,k).__of__(o)

    If "self" is an implicit wrapper itself,
    then acquisition may be used to look up "k".



This implies, that the idiom

	<dtml-if "_.hasattr(o.aq_explicit,XXXX)">

cannot be used safely to test, whether "o" has attribute
XXXX itself (rather than acquired it).
We probably should have a standard function for this kind
of test.


Dieter