Re: [Zope-dev] Acquisition wishlist :-)
On Mon, Jan 08, 2001 at 10:38:22PM +0100, Dieter Maurer wrote: Martijn Pieters writes: On Mon, Jan 08, 2001 at 10:10:34AM +, Chris Withers wrote: You wouldn't need to have index_html = None if it is inherited, since the inherited idnex_html would be used before one is acquired, surely? Yup. If you don't want to have any index_html *at all*, just declare it index_html = None. DTML Methods and HiperDom templates do this as well, for example. You have an "index_html" and its value is "None". If you use this class with another class that has a useful "index_html", you must care for the inheritance order to get the right on. Of course, but you always have to. index_html in any class could be anything. You could even override the inherited 'index_html = None' with 'index_html = Acquisition.Acquire'. -- Martijn Pieters | Software Engineer mailto:[EMAIL PROTECTED] | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ - ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] Acquisition wishlist :-)
Dieter Maurer wrote: Chris Withers writes: And I suppose the other part of my wishlist: class MyClass(Acquisition.Implicit): # your_attribute will be acquied # index_html won't index_html = None No, that is not enough! As a side effect to turn off acquisition, you defined the attribute. This will not play well with inheritance: You will not only prevent acquisition of "index_html" but also prevent inheritance of it (which may be really necessary in some contexts). I'm pretty sure inheritence takes precedence over Acquisition. You wouldn't need to have index_html = None if it is inherited, since the inherited idnex_html would be used before one is acquired, surely? cheers, Chris ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] Acquisition wishlist :-)
On Mon, Jan 08, 2001 at 10:10:34AM +, Chris Withers wrote: Dieter Maurer wrote: Chris Withers writes: And I suppose the other part of my wishlist: class MyClass(Acquisition.Implicit): # your_attribute will be acquied # index_html won't index_html = None No, that is not enough! As a side effect to turn off acquisition, you defined the attribute. This will not play well with inheritance: You will not only prevent acquisition of "index_html" but also prevent inheritance of it (which may be really necessary in some contexts). I'm pretty sure inheritence takes precedence over Acquisition. You wouldn't need to have index_html = None if it is inherited, since the inherited idnex_html would be used before one is acquired, surely? Yup. If you don't want to have any index_html *at all*, just declare it index_html = None. DTML Methods and HiperDom templates do this as well, for example. -- Martijn Pieters | Software Engineer mailto:[EMAIL PROTECTED] | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ - ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] Acquisition wishlist :-)
Martijn Pieters writes: On Mon, Jan 08, 2001 at 10:10:34AM +, Chris Withers wrote: You wouldn't need to have index_html = None if it is inherited, since the inherited idnex_html would be used before one is acquired, surely? Yup. If you don't want to have any index_html *at all*, just declare it index_html = None. DTML Methods and HiperDom templates do this as well, for example. You have an "index_html" and its value is "None". If you use this class with another class that has a useful "index_html", you must care for the inheritance order to get the right on. Dieter ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] Acquisition wishlist :-)
Chris Withers writes: Dieter Maurer wrote: Chris Withers writes: And I suppose the other part of my wishlist: class MyClass(Acquisition.Implicit): # your_attribute will be acquied # index_html won't index_html = None No, that is not enough! As a side effect to turn off acquisition, you defined the attribute. This will not play well with inheritance: You will not only prevent acquisition of "index_html" but also prevent inheritance of it (which may be really necessary in some contexts). I'm pretty sure inheritence takes precedence over Acquisition. You wouldn't need to have index_html = None if it is inherited, since the inherited idnex_html would be used before one is acquired, surely? Of cause, but that's unfortunately only a local view. In Python (and Zope) you have multiple inheritance and mixin classes. You do not know with what classes you (or someone else) will combine a class at hand. If it is good in one context to disable acquisition for a method because the class does not provide a usefull definition but still does not want to inherit it, then in a different context, the method should be provided by an inherited class. A good example is "objectValues" and friends. "SimpleItem.Item" defines them to return empty tuples (to prevent acquisition from the containing container), but if you combine a class derived from "SimpleItem.Item" with an ObjectManager, you want the ObjectManager's "objectValues" and not that stupid method from "Item". It would be much clearer, when "Item" could declare, it does not want to acquire the methods without providing a definition. Dieter ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] Acquisition wishlist :-)
On Thu, Jan 04, 2001 at 10:46:35AM +, 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:[EMAIL PROTECTED] | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ - ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] Acquisition wishlist :-)
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 +, 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:[EMAIL PROTECTED] | Digital Creations http://www.digicool.com/ | Creators of Zope http://www.zope.org/ - ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 ) ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] Acquisition wishlist :-)
Shane Hathaway wrote: There's a (much) simpler way: class MyClass(Acquisition.Explicit): your_attribute = Acquisition.Acquired # index_html isn't index_html = None Cool :-) And I suppose the other part of my wishlist: class MyClass(Acquisition.Implicit): # your_attribute will be acquied # index_html won't index_html = None Sorry for wasting the lists' time :-S Chris ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] Acquisition wishlist :-)
Chris Withers writes: And I suppose the other part of my wishlist: class MyClass(Acquisition.Implicit): # your_attribute will be acquied # index_html won't index_html = None No, that is not enough! As a side effect to turn off acquisition, you defined the attribute. This will not play well with inheritance: You will not only prevent acquisition of "index_html" but also prevent inheritance of it (which may be really necessary in some contexts). Dieter ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] Acquisition wishlist :-)
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. cheers, Chris Dieter ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 ) ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )
Re: [Zope-dev] Acquisition wishlist :-)
Jim Fulton wrote: I'm inclined to think that in some future version of Zope, we should switch to making explicit acquisition the norm. Well, implicit is good when you're starting, but can cause fun with security later. Hmmm, I guess I like the way it is but my wishlist (damn, Christmas just gone ;-) would be: for Acquisiton.Implicit, be able to do something like: class MyClass (Acquisition.Implicit): acquisition = ClassAcquisitionInfo() acquisition.donotacquire('index_html') and, likewise, for Acquisition.Explicit, to be able to to something like: class MyClass (Acquisition.Explicit): acquisition = ClassAcquisitionInfo() acquisition.acquire('index_html') acquisition.acquire('fred') ...of course, you may be able to do this already in some way. What do people think? cheers, Chris ___ Zope-Dev maillist - [EMAIL PROTECTED] 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 )