[Zope-dev] Re: ComputedAttribute
Martijn Pieters
mj@digicool.com
Fri, 5 Jan 2001 13:54:54 +0100
On Fri, Jan 05, 2001 at 12:22:32PM +0000, Chris Withers wrote:
> Martijn Pieters wrote:
> >
> > You could use ComputedAttribute for that:
> >
> > class MyClass(Acquisition.Explicit):
> > # The following attribute is acquired transparently
> > def _acquired_your_attribute(self):
> > return self.aq_acquire('your_attribute')
> > your_attribute = ComputedAttribute(_acquired_your_attribute, 1)
> >
> > # index_html isn't
> > index_html = None
>
> That looks cool :-)
>
> Where's it documented? what does the 1 mean?
Erm. The ExtensionClass.stx documentation hints at a ComputedAttribute
class (but as an example of how you could use an ExtensionClass). The
current C implementation of ComputedAttribute is not, as far as I can see,
documented.
As for the '1', the CVS log has the following to say on that:
Added second "level" argument for computed attributes. This makes it
easier to create computed attributes that work with acquisition.
Normally, computed attributes are called with unwrapped objects. Passing
a level of 1, causes computed attributes to be called with one level of
wrapping. Note that the innermost (single) level of wrapping typically
reflects a containment context with any extra access contexts stripped
off.
As I understand it, it makes self.aq_acquire possible.
See also:
http://cvs.zope.org/Zope2/lib/Components/ExtensionClass/ComputedAttribute.c
--
Martijn Pieters
| Software Engineer mailto:mj@digicool.com
| Digital Creations http://www.digicool.com/
| Creators of Zope http://www.zope.org/
---------------------------------------------