[Zope] __getattr__ and getPhysicalRoot()

Stefan Bund l-zope.z.xalan at xoxy.net
Thu Apr 29 11:17:17 EDT 2004


Hello list,

I have been trying to implement a special __getattr__ hook now for
some time and have come to a dead end. I know, __getattr__ hooks are
evil and you should never need theme. I have read the threads about
__getattr__ in the zope-dev list-archive. But I still need this.

I want to implement a special reference pattern (Something like a
combination of PortableHole and TransparentFolder). To this end, I
need access to a Zope object specified by its absolute path
(getPhysicalPath()) inside the __getattr__ method. The Problem is,
__getattr__ is often called without an acquisition wrapper and
therefore has no direct access to the Zope root object.

I started to dissect the ZPublisher, ZServer, HTTPServer, HTTPRequest,
Zope.App.startup.startup and some other source code only to find, that
there seems to be *no* way to get at the *current* root object
instance for the current thread, since __bobo_traverse__ of
ZODB.ZApplication.ZApplicationWrapper does not save the root object
anywhere. But I really can't open and close a new ZODB connection
inside a __getattr__ hook ...

Is there any way out of this dilemma? I Looked and ProtableHole's
source, but the solution there doesn't work for me (getPysicalRoot is
only defined in Application and is set to Acquisition.Acquired in
Traversable. Without an acquisition context this doesn't help much
;-/)

If there is no way to solve this problem, I'll have to use my second
best solution and refactor my solution so I can override __of__ instead
of __getattr__, but the __getattr__ solution would be much more
flexible ...

Stefan.

-- 
-- *DON'T* TRY TO REACH ME DIRECTLY AT ABOVE EMAIL ADDRESS. Any reply
-- received off-list at that address will be *silently* and
-- *unconditionally* dropped. You can attribute this inconvenience to
-- the proliferation of spammers on the Internet. I hope, you can
-- understand my position and accept my counter measures.



More information about the Zope mailing list