Problems with non-zope object attribute access
Hello, I have this serious show-stopper problem that I do not know how to get around, so any input is appreciated. I am building a Product that is basically a Zope interface to a set of non-Zope APIs to a directory system. In my product at one point I receive a list of (not zope-based) objects from a factory method in the API set. These objects all represent Persons with all necesary attributes and lazy DB lookup etc. Very neat. What is not so neat is that I have no means of zope-unpack them and display them in a ZPT. I have tried the following in my product class: def _zopify(self, o): # wrap object o in a an Acquisition.ImplicitAcquisitionWrapper # add __allow_access_to_unprotected_subobjects = 1 # Return o o.__allow_access_to_unprotected_subobjects = 1 return Acquisition.ImplicitAcquisitionWrapper(o, self) and in my product code I do this. plist = get_non_zope_person_object_list(...) return [self._zopify(person) for person in plist ] but I still get """ The container has no security assertions. Access to 'lname' of (Products.pdbapi.person.Person instance at 0x03449DA0) denied. """ errors when I try to access the attributes of a person object in the list. I am very reluctant to add zope-specific stuff to the set of APIs because they are used in several other places that are not Zope-specific. I also would like not to have to duplicate code existing in the API just to have it become Zope-friendly, so I am trying to find alternative paths here. Any help is appreciated. Thanks, /dario -- -- ------------------------------------------------------------------- Dario Lopez-Kästen, IT Systems & Services Chalmers University of Tech. "...and click? damn, I need to kill -9 Word again..." - b using macosx
Dario Lopez-Kästen wrote:
but I still get
""" The container has no security assertions. Access to 'lname' of (Products.pdbapi.person.Person instance at 0x03449DA0) denied. """
errors when I try to access the attributes of a person object in the list.
What about wrapping them with something like? class AccessWrapper: __allow_access_to_unprotected_subobjects = 1 def __init__(self, obj): self._obj = obj def __getattr__(self, attr): return getattr(self._obj) -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science
Dario Lopez-Kästen wrote:
I have tried the following in my product class:
def _zopify(self, o): # wrap object o in a an Acquisition.ImplicitAcquisitionWrapper # add __allow_access_to_unprotected_subobjects = 1 # Return o o.__allow_access_to_unprotected_subobjects = 1 return Acquisition.ImplicitAcquisitionWrapper(o, self)
and in my product code I do this.
plist = get_non_zope_person_object_list(...) return [self._zopify(person) for person in plist ]
btw. if setting __allow_access_to_unprotected_subobjects = 1 on the object doesn't work, the ImplicitAcquisitionWrapper most likely sets it to something else. have you tried changing the order? w = Acquisition.ImplicitAcquisitionWrapper(o, self) w.__allow_access_to_unprotected_subobjects = 1 return w -- hilsen/regards Max M, Denmark http://www.mxm.dk/ IT's Mad Science
Max M wrote:
btw. if setting __allow_access_to_unprotected_subobjects = 1 on the object doesn't work, the ImplicitAcquisitionWrapper most likely sets it to something else.
have you tried changing the order?
w = Acquisition.ImplicitAcquisitionWrapper(o, self) w.__allow_access_to_unprotected_subobjects = 1 return w
turns out to be a spelling error. Did a search for "allow_access_to" in lib/python. It gave me the following knowledge (: Wrong spelling: __allow_access_to_unprotected_subobjects Correct spelling: __allow_access_to_unprotected_subobjects__ after that, it works like a charm! Thanks for all the help though, it showed some neat techniques that may come in handy in the future. Cheers, /dario -- -- ------------------------------------------------------------------- Dario Lopez-Kästen, IT Systems & Services Chalmers University of Tech. "...and click? damn, I need to kill -9 Word again..." - b using macosx
participants (2)
-
Dario Lopez-Kästen -
Max M