Set "uncontained" attributes on a Implicitly wrapped object.
I already found a solution for this but I'm asking to see if there might be another way to do this? I need to save a referens to a acquision wrapped object "Configure" in a object which at some point doesn't have it's own context (just a single wrapped object). I save this volatile and always uniquely for each REQUEST object (see CMF skinable for an example). Just assigning it to the attribute self._v_skinfolder=sf and the accessing it as self.skinfolder makes it contained in the object (aq_chain would say [<Skinfolder>, <Object>]) But by saving it as a tuple: self._v_skinfolder=(sf,) it's not directly contained in the <Object> so when accessing it self.skinfolder[0] it's returned with its original context. Is there anyway to make uncontained attributes of an object that inherits Acquisision.Implicit? Cheers, Johan Carlsson -- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72 Email: johanc@easypublisher.com SE-113 37 STOCKHOLM
Not quite sure what the end result is you want, or that I understand you question - do you want it wrapped or not? Anyway, to unwrap the object I do the following: unwrappedOb = Acquisition.aq_base(wrappedOb) unwrappedOb.someAttribute #this will now not traverse to the aq_parents to search if this attr doesn't exist. this is better than ob.aq_base as it works for "unwrapped" objects too without raising an AttributeError if the ob doesn't have the aq_base. To wrap the object with an acquisition context (not sure my lingo is correct here), I've had joy with: wrappedOb = Acquisition.ImplicitAcquisitionWrapper([unwrappedOb,self]) where self could be anything already Acquisition wrapped. HTH Etienne At 06:36 PM 17/7/2003 +0200, Johan Carlsson wrote:
I already found a solution for this but I'm asking to see if there might be another way to do this?
I need to save a referens to a acquision wrapped object "Configure" in a object which at some point doesn't have it's own context (just a single wrapped object).
I save this volatile and always uniquely for each REQUEST object (see CMF skinable for an example).
Just assigning it to the attribute self._v_skinfolder=sf and the accessing it as self.skinfolder makes it contained in the object (aq_chain would say [<Skinfolder>, <Object>])
But by saving it as a tuple: self._v_skinfolder=(sf,) it's not directly contained in the <Object> so when accessing it self.skinfolder[0] it's returned with its original context.
Is there anyway to make uncontained attributes of an object that inherits Acquisision.Implicit?
Cheers, Johan Carlsson
-- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72 Email: johanc@easypublisher.com SE-113 37 STOCKHOLM
_______________________________________________ Zope maillist - Zope@zope.org http://mail.zope.org/mailman/listinfo/zope ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope-dev )
Etienne Labuschagne wrote:
Not quite sure what the end result is you want, or that I understand you question - do you want it wrapped or not?
I want to preserve the original wrapping, which will be destroyed if I save the wrapping to an attribute. But if I first put the reference in a tuple (which doesn't support Acquisition) the original context is preserve. I guess I'm looking for a AntiWrapper looking like this: class AntiWrapper: #Don't inherit Acquisition.Implicit def __init__(self, wrapped_obj): self.wrapped_obj=wrapped_obj def getObjectWrapper(self): return self.wrapped_obj But never mind. I'm just looking for some ZopeZen that ยจ I don't really need. Using a tuple works, it's a hack but it works. Cheers, Johan -- Johan Carlsson Tel: + 46 8 31 24 94 Colliberty Mob: + 46 70 558 25 24 Torsgatan 72 Email: johanc@easypublisher.com SE-113 37 STOCKHOLM
Johan Carlsson wrote at 2003-7-17 18:36 +0200:
... I need to save a referens to a acquision wrapped object "Configure" in a object which at some point doesn't have it's own context (just a single wrapped object). ... Just assigning it to the attribute self._v_skinfolder=sf and the accessing it as self.skinfolder makes it contained in the object (aq_chain would say [<Skinfolder>, <Object>])
This is not the case: Only if an object is unwrapped, is the container of "AcquisitionWrapper(object,parent)" determined by "parent". Otherwise, its container is the container of object. To say it differently: The container of an acquisition wrapped object "o" is "o.aq_inner.aq_parent". If "o" is "AcquistionWrapper(self,parent)" with "self" unwrapped, then "o.aq_inner" is "o". Otherwise, "o.aq_inner" is "self.aq_inner".
... Is there anyway to make uncontained attributes of an object that inherits Acquisision.Implicit?
No, if the container is an "ExtensionClass" instance. Any "ExtensionClass" attribute lookup checks whether the looked up object has an "__of__" method and calls it in this case. The usual way to avoid this mechanism is to access the attribute via "self.__dict__['attribute']". Dieter
participants (3)
-
Dieter Maurer -
Etienne Labuschagne -
Johan Carlsson