[Zope] Inserting objects in acquisition chain

Oliver Bleutgen myzope@gmx.net
Thu, 15 Nov 2001 19:12:10 +0100


Casey, Dieter thanks for your answer.

Dieter wrote:
 > Have a look at "TransparentFolder" or my product "Mirroring Folder".
 >
 > Neither does, what you want but you can see how to achieve
 > this...

Hmm,
I looked at similiar products before asking this, but I don't think they 
do what I want. TransparentFolder  patches zope, I would like to avoid 
that.
As far as I understand, your Mirroring Folder doesn't insert an object
into the namespace, it appends it.

What I want to do is something like Casey wrote:


 > Assuming you want the effect to be temporary, that is only within the 
 > product code, you can do:
 >
 > new_wrapper = subobject.aq_base.__of__(parent_object)
 >
 > If subobject is not already an acquisition wrapper then this would
 > do:
 > new_wrapper = subobject.__of__(parent_object)

But I want it permanently. And that was what I'm trying to do 
(unsuccessfully) for a while, overriding __of__:

[...]
     __old_of__ = Folder.__of__

     def __of__(self,parent):
         t = getattr(self,'subfolder')
         wrapped_template = t.aq_base.__of__(parent)
         wrapped_self = self.__old_of__(wrapped_template)
     return wrapped_self


The product inherits from OFS.Folder, subfolder is a plain folder.
It doesn't work, trying to get any attribut of an instance gives an 
unauthorized error (sorry for the wrapping)
[...]

   File 
/home/bleutgen/bin/Zope-2.4.3b1-src/lib/python/AccessControl/ZopeGuards.py, 
line 103, in aq_validate
     (Object: testordner)
   File 
/home/bleutgen/bin/Zope-2.4.3b1-src/lib/python/AccessControl/SecurityManager.py, 
line 149, in validate
   File 
/home/bleutgen/bin/Zope-2.4.3b1-src/lib/python/AccessControl/ZopeSecurityPolicy.py, 
line 229, in validate
Unauthorized: (see above)