[Zope] UNEXPECTED: Acquisition.Explicit may acquire implicitly
Pierre-Julien Grizel
grizel@mouli.net
Tue, 02 Jan 2001 15:32:54 +0100
Dieter Maurer wrote:
>
> 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.
Mhhh .... Something like "<dtml-if "_.hasattr(o.aq_base,XXXX)">" ?
P.-J.
>
> Dieter
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
--
If the only tool you have is a hammer,
you tend to see every problem as a nail.
Si le seul outil dont vous disposez est un marteau,
vous avez tendance à voir chaque problème comme un clou.
--Abraham Maslow