Losing acquisition wrapping between method calls
I get a problem where "self" loses it's acquisition wrapping between method calls. It happens as follows: Defintion: ========== class MyClass(CatalogAware, SimpleItem): # snip def fancySetattr(self, attrName, attrValue): self.__dict__['_dyn_%s' %attrName] = attrValue self.reindex_object() MyClass.__setattr__ = fancySetattr Usage: ====== #get MyClass instance myInstance = folder.restrictedTraverse("Instance1") myInstance.aq_parent #works ok myInstance.name = "John" Problem: ======== when stepping into the above code, I end up, as expected, in fancySetattr with "self" being myInstance. All is fine, except for the fact that "self" is no longer acquisition wrapped thus the self.reindex_object() line does not work as it is dependant on being able to acquire the catalog, which it can't. Why does myInstance lose it's acquisition wrapper once it is passed to fancySetattr as "self"? Is there a way to re-wrap it or not lose the wrapping at all? Any help would be appreciated! Etienne Running Zope2.7 rc1 on Window 2000 with Python 2.3.3 (Windows binary dist)
LabuComp wrote at 2004-2-5 00:15 +0200:
I get a problem where "self" loses it's acquisition wrapping between method calls.
Several low level methods as called without acquisition context. The most prominent examples are: "__init__", "__getattr__", "__setattr__". Use mutators instead of direct attribute assignment. -- Dieter
Thanks for the reply Dieter, The example below is very brief and gives the impression of direct attribute assignment. What I was actually trying to acomplish is to implement properties in Zope by using __getattr__ and __setattr__. This way of implementing properties is currently the only option in Zope afaik (unless I can get ZODB 3.3 to work for me) as new style classes are not yet supported in ZODB 3.2. Properties will give me the syntaxical ease of direct attribute access, but with the "correctness" of accessors (getters and setters). It seems that although I can have properties, I will have limited (Zopeish) scope on what I can do in the setter. Hopefully I can make ZODB 3.3 work with Zope2.7 and have the best of both worlds (new-style classes's properties in Zope - yeeehaaa). Regards Etienne At 07:36 PM 5/2/2004 +0100, Dieter Maurer wrote:
LabuComp wrote at 2004-2-5 00:15 +0200:
I get a problem where "self" loses it's acquisition wrapping between method calls.
Several low level methods as called without acquisition context. The most prominent examples are: "__init__", "__getattr__", "__setattr__".
Use mutators instead of direct attribute assignment.
-- Dieter
_______________________________________________ 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 )
participants (3)
-
Dieter Maurer -
Etienne Labuschagne -
LabuComp