[Zope] Need help with acquisition

Roché Compaan roche@upfrontsystems.co.za
Fri, 25 Apr 2003 12:56:23 +0200


Answering my own question. I was a too impatient with __of__. I now
return 'self' unwrapped until the parent is wrapped which works fine:

    def __of__(self, parent, _iaw=ImplicitAcquisitionWrapper):
        if type(parent) is not _iaw or not hasattr(parent,'REQUEST'):
            return self

        w_self = _iaw(self,parent)

        ob = parent.aq_acquire('object_to_acquire')
        w_self.x = ob.function()

        return w_self


On Fri, 25 Apr 2003 10:58:18 +0200
Roché Compaan <roche@upfrontsystems.co.za> wrote:

> Hi there
> 
> I want to override __of__ on a ObjectManager subclass to set an
> attribute on 'self' but I am having trouble with acquisition.
> After I've wrapped 'self' with ImplicitAcquisitionWrapper I still can't
> acquire objects higher up in the acquisition tree. It seems as if self
> is wrapped in the context of its parent but the parent remains
> unwrapped.
> 
>     def __of__(self, parent):
>         w_self = ImplicitAcquisitionWrapper(aq_base(self), parent)
>         w_self.x = w_self.acquired_object.function()
>         return w_self
> 
> I also tried overriding __getattr__ but then 'self' is also unwrapped and
> I don't think I can wrap it there anyway since I don't have access to
> its parent.
> 
> Any ideas on how to do this?
> 
> -- 
> Roché Compaan
> Upfront Systems                 http://www.upfrontsystems.co.za
> 
> _______________________________________________
> 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 )


-- 
Roché Compaan
Upfront Systems                 http://www.upfrontsystems.co.za