Re: [Zope] Re: Getting a methods parent (in a product)
Tres Seaver wrote: The actual issue is that attribute access will break if you have an unwrapped object; 'aq_parent(foo)' will return 'None' in that case. AttributeError: aq_parent AttributeEror: None has no attribute myattribute Take your pick I guess ;-) *grinz* Chris -- Simplistix - Content Management, Zope Python Consulting - http://www.simplistix.co.uk ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] Re: Getting a methods parent (in a product)
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Jens Vagelpohl wrote: On 23 Jul 2005, at 16:12, Peter Bengtsson wrote: from Acquisition import aq_inner, aq_parent parent = aq_parent(aq_inner(self)) This will return the true container the instance is set in, not just the acquisition parent. What's so bad about parent = self.aq_parent Two things: - simply using aq_parent does not guarantee giving you the real containment parent. Depending on the path used to access the object it could be something different from the true containment parent. That's the power of acquisition... Which is why the 'aq_inner()' call is in there: it strips away non-contaiment wrappers. - direct attribute access like that makes me feel dirty. I prefer the true object-oriented style where you use methods to get at stuff. The actual issue is that attribute access will break if you have an unwrapped object; 'aq_parent(foo)' will return 'None' in that case. (A tiny nit, 'aq_parent()' and the related 'aq_base()' and 'aq_inner()' are module-scope functions, rather than methods). Tres. - -- === Tres Seaver +1 202-558-7113 [EMAIL PROTECTED] Palladion Software Excellence by Designhttp://palladion.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFC5EZx+gerLs4ltQ4RAk9+AKCsb9wg7edRq4HfFcHn/FwBvpSmCwCeK8Ke zt8foauYT7v9DRf2TYbqMjE= =eU4v -END PGP SIGNATURE- ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
[Zope] Re: Getting a methods parent (in a product)
How can I get a Product instance's _actual_ parent when one of its methods is called? (In other ways: how can I find out, from an instance, where that instance is located without falling prey to acquisition in Zope 2?) from Acquisition import aq_inner, aq_parent parent = aq_parent(aq_inner(self)) This will return the true container the instance is set in, not just the acquisition parent. What's so bad about parent = self.aq_parent ? jens ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev ) -- Peter Bengtsson, work www.fry-it.com home www.peterbe.com hobby www.issuetrackerproduct.com ___ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )