Thanks for the reply.

Steve Alexander wrote:
> Sounds like you could use ZPatterns.
We already use ZPatterns, but that doesn't seem to fit in at the right
layer unfortunately.  To further clarify...
I am trying to do something similar to what is implemented in Dieter
Maurer's 'Reference' product (ie. access another object via a
link/reference), and be able to check elswhere for a method/attribute
and return it in preference to acquisition (both containment & context
based), but not break the acquisition.  When I first looked at this
product I didn't think it did this quite how I wanted, but I may not
have been using it right, as then answer seems to be there, override the
__of__ method, and ditch __getattr__!

As it stands, I see (think) the standard attribute/method search happens
for an Implicit derived class as follows :

1 - Check instance, self.__dict__
2 - Check class, self.__class__.__dict__
3 - Check base classes dict, self.__class__.__bases__ __dict__'s etc.
4 - If not found then look for a __getattr__ method and call it. This is
implemented in Acquisition.Implicit (c based Extension Class).
5 - Implicit __getattr__ does containment aquisition, __of__. 
6 - Implicit __getattr__ does context aquisition, __bobo_traverse__.

Overriding __of__ by doing something like :

    def __of__(self, parent):
        if not hasattr(parent,'aq_base'): return self 
        ob = self.getTarget()
        self = Acquisition.ImplicitAcquisitionWrapper(self, ob)
        self = Acquisition.ImplicitAcquisitionWrapper(self, parent)
        return self

Seems to do the trick as it puts the referenced or linked object in the
acquisition chain before the parent.  I'm still curious as to know how
to get this working with __getattr__ but this other way seems to achieve
the same end, and in a similarly elegant fashion.


Zope-Dev maillist  -  [EMAIL PROTECTED]
**  No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to