Pregunta

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.

¿Fue útil?

Solución

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top