inserting uncle into acquisition chain
I've got an __of__ function: def __of__(self, parent): if not hasattr(self, 'aq_parent'): return ImplicitAcquisitionWrapper(self, parent) else: category = parent.unrestrictedTraverse(self._category._path) return ImplicitAcquisitionWrapper(self, category.__of__(parent)) The goal is to insert another object (self._category) into my objects context (so security settings on the category can be inherited by this object). It mostly works, however the chain is broken above my containing parent: ob.aq_inner.aq_parent -- is not a wrapper This results in all kinds of failures in ZopeSecurityPolicy.validate. Any suggestions? I still don't fully understand how this is supposed to work. Thanks, -Randy
From: "Randall F. Kern" <randy@spoke.net>
def __of__(self, parent): if not hasattr(self, 'aq_parent'): return ImplicitAcquisitionWrapper(self, parent) else: category = parent.unrestrictedTraverse(self._category._path) return ImplicitAcquisitionWrapper(self, category.__of__(parent))
This is genuine deep-down hard stuff. It's not too hard to make an acquisition wrapper, as you're doing, but there are subtle implications in the way it's constructed. Many parts of Zope assume that an object's wrapper was produced normally, and that therefore you can follow the containment chain by repeatedly taking the aq_inner.aq_parent. Your inserted object therefore ends up hijacking containment (with security effects) or worse, cutting containment short. I *think* that you might get something resembling the effect you're looking for with this: def __of__(self, parent): if not hasattr(self, 'aq_parent'): parent = parent.unrestrictedTraverse(self._category._path) return ImplicitAcquisitionWrapper(self, parent) Cheers, Evan @ digicool & 4-am
participants (2)
-
Evan Simpson -
Randall F. Kern