Getting a methods parent (in a product)
Hi! 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?) TIA, Ole
On 22 Jul 2005, at 18:48, Jan-Ole Esleben wrote:
Hi!
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. jens
Thanks a lot, I'll try that. Ole 2005/7/22, Jens Vagelpohl <jens@dataflake.org>:
On 22 Jul 2005, at 18:48, Jan-Ole Esleben wrote:
Hi!
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.
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 )
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
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... - direct attribute access like that makes me feel dirty. I prefer the true object-oriented style where you use methods to get at stuff. jens
-----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 tseaver@palladion.com Palladion Software "Excellence by Design" http://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-----
Dear All, I try to install Zope 2.7.0 in my machine. This version is installed successfully but after the installation I try to run zope service using runzope command. But I got below error. I am using gobolinux and Python 2.3.3 for this zope version. I try to install some other zope version eg (2.7.6,2.8.0 and 3.0.0) all the different version of zope have the same problem. Kindly let me know what is the problem of zope installation. regards Prabahar gobo@prabahar /Users/enmail/tes]bin/runzope ------ 2005-07-25T10:39:52 INFO(0) ZServer HTTP server started at Mon Jul 25 10:39:52 2005 Hostname: localhost.localdomain Port: 8080 ------ 2005-07-25T10:39:52 INFO(0) ZServer FTP server started at Mon Jul 25 10:39:52 2005 Hostname: prabahar Port: 8021 ------ 2005-07-25T10:39:52 INFO(0) Zope Set effective user to "enmail" Traceback (most recent call last): File "/Programs/Zope/2.7.0/lib/python/Zope/Startup/run.py", line 49, in ? run() File "/Programs/Zope/2.7.0/lib/python/Zope/Startup/run.py", line 19, in run start_zope(opts.configroot) File "/Programs/Zope/2.7.0/lib/python/Zope/Startup/__init__.py", line 51, in start_zope starter.startZope() File "/Programs/Zope/2.7.0/lib/python/Zope/Startup/__init__.py", line 230, in startZope Zope.startup() File "/Programs/Zope/2.7.0/lib/python/Zope/__init__.py", line 45, in startup from Zope.App.startup import startup as _startup File "/Programs/Zope/2.7.0/lib/python/Zope/App/startup.py", line 30, in ? import OFS.Application File "/Programs/Zope/2.7.0/lib/python/OFS/Application.py", line 18, in ? import Globals,Folder,os,sys,App.Product, App.ProductRegistry, misc_ File "/Programs/Zope/2.7.0/lib/python/App/Product.py", line 44, in ? from HelpSys.HelpSys import ProductHelp File "/Programs/Zope/2.7.0/lib/python/HelpSys/__init__.py", line 15, in ? import HelpSys File "/Programs/Zope/2.7.0/lib/python/HelpSys/HelpSys.py", line 18, in ? from Products.ZCatalog.ZCatalog import ZCatalog File "/Programs/Zope/2.7.0/lib/python/Products/ZCatalog/__init__.py", line 16, in ? import ZCatalog, Catalog, CatalogAwareness, CatalogPathAwareness, ZClasses File "/Programs/Zope/2.7.0/lib/python/Products/ZCatalog/ZCatalog.py", line 39, in ? from IZCatalog import IZCatalog File "/Programs/Zope/2.7.0/lib/python/Products/ZCatalog/IZCatalog.py", line 236, in ? __doc__ = IZCatalog.__doc__ + __doc__ TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType' __________________________________________________________ Free antispam, antivirus and 1GB to save all your messages Only in Yahoo! Mail: http://in.mail.yahoo.com
praba kar wrote at 2005-7-25 06:25 +0100:
... "/Programs/Zope/2.7.0/lib/python/Products/ZCatalog/IZCatalog.py", line 236, in ? __doc__ = IZCatalog.__doc__ + __doc__ TypeError: unsupported operand type(s) for +: 'NoneType' and 'NoneType'
".0" releases often have problems. I recommend to switch to the latest "2.7" release (which is 2.7.7 or maybe even 2.7.8). -- Dieter
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
participants (7)
-
Chris Withers -
Dieter Maurer -
Jan-Ole Esleben -
Jens Vagelpohl -
Peter Bengtsson -
praba kar -
Tres Seaver