[Zope-dev] Acquisition wishlist :-)

Shane Hathaway shane@digicool.com
Fri, 05 Jan 2001 10:59:09 -0500


There's a (much) simpler way:

class MyClass(Acquisition.Explicit):
    your_attribute = Acquisition.Acquired

    # index_html isn't
    index_html = None

"Acquired" is a special object that the acquisition module looks for.

However, I wasn't aware you could add a "1" to the ComputedAttribute
constructor.  Thanks!

Shane

Martijn Pieters wrote:
> 
> On Thu, Jan 04, 2001 at 10:46:35AM +0000, Chris Withers wrote:
> > Dieter Maurer wrote:
> > >
> > >  >      acquisition.donotacquire('index_html')
> > > This would be great.
> >
> > Indeed :-)
> >
> > >  > class MyClass (Acquisition.Explicit):
> > >  >
> > >  >      acquisition = ClassAcquisitionInfo()
> > >  >
> > >  >      acquisition.acquire('index_html')
> > >  >      acquisition.acquire('fred')
> > > You already can do that, though with a different syntax
> > > (I would need to search for in the documentation).
> >
> > You may mean that if x is an Acquisition.Explicit object, you can do:
> >
> > x.aq_acquire('your_attribute') (syntax may be wrong ;-)
> >
> > What I meant is that through a declaration in the class you could saying
> > acquire the 'your_attribute' attribute but nothing else. So, you could
> > still do:
> >
> > x.your_attribute ...which would be acquired, but...
> > x.index_html     ...which wouldn't be acquired.
> 
> 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
> 
> Or you could define a __getattr__ that does a lookup in a list for
> explicetly acquired attributes:
> 
>     _acquired = ('index_html', 'fred')
>     def __getitem__(self, key):
>         if key in self._acquired:
>             return self.aq_acquire(key)
>         raise AttributeError, name
> 
> --
> Martijn Pieters
> | Software Engineer  mailto:mj@digicool.com
> | Digital Creations  http://www.digicool.com/
> | Creators of Zope   http://www.zope.org/
> ---------------------------------------------
> 
> _______________________________________________
> Zope-Dev maillist  -  Zope-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zope-dev
> **  No cross posts or HTML encoding!  **
> (Related lists -
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope )