0

Essentially, I want to check another object to see if an attribute is set there before processing the items in object.aq_chain.

I can't seem to avoid infinite recursion when overriding getattr and getattribute.

UPDATE

Example:

import ExtensionClass, Acquisition

class Folder(ExtensionClass.Base): pass

class File(Acquisition.Implicit): pass

parent1 = Folder()
parent1.foo = 1
parent2 = Folder()
parent2.foo = 2

child = File()
parent1.child = child
child.otherparent = parent2

print parent1.child.foo # prints 1, but i want it to print 2

In case it does not go without saying, there is an API I am trying to work within.

Ben
  • 2,422
  • 2
  • 16
  • 23
  • Could you please provide concrete example. You can always use special attribute access methods, which do not trigger acquisition, but it is hard to tell anything without concrete example. – Roman Susi Jan 13 '12 at 18:56

1 Answers1

0

To build acquisition chains, you need to use the __of__ method of the Acquisition wrapper:

>>> wrapped = child.__of__(parent2)
>>> assert wrapped.aq_parent is parent2
True

See the Acquisition chapter of the Zope2 documentation for more information.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343