Hi, I made a Product class with unpicklable attributes (compiled TALES expressions). Thus I got to name those _v_foo But for re-creating these attributes, I need to have a hook method called when the object is extracted from ZODB. Is there such a hook method in Zope core classes ? Thanks in advance. --Gilles
my general solution is something like that: class foo: def somemethod(self): myattr = self.getmyattr() def getmyattr(self): if not hasattr(self, '_v_myattr'): myattr = <do something to ...> else: myattr = getattr('_v_myattr'): return myattr -aj --On Montag, 28. Juli 2003 15:49 Uhr +0200 Gilles Lenfant <gilles@pilotsystems.net> wrote:
Hi,
I made a Product class with unpicklable attributes (compiled TALES expressions). Thus I got to name those _v_foo But for re-creating these attributes, I need to have a hook method called when the object is extracted from ZODB.
Is there such a hook method in Zope core classes ?
Thanks in advance.
--Gilles
_______________________________________________ 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 )
----- Original Message ----- From: "Andreas Jung" <andreas@andreas-jung.com> To: "Gilles Lenfant" <gilles@pilotsystems.net>; <zope@zope.org> Sent: Monday, July 28, 2003 3:42 PM Subject: Re: [Zope] Object
my general solution is something like that:
class foo:
def somemethod(self):
myattr = self.getmyattr()
def getmyattr(self): if not hasattr(self, '_v_myattr'): myattr = <do something to ...> else: myattr = getattr('_v_myattr'): return myattr
Thanks Andreas, I already done something like this that works, but I just wanted to know if this could be done when the object is extracted from the ZODB to the cache. Something more elegant like: def after_cache(self): self._v_mystuff = ... return Cheers --Gilles
You can define a __setstate__ method, but be aware that it has some restrictions, such as self not being acquisition wrapped. If you need those features of a fully instantiated published object, then attribute checks in a getter will allow you to test for the presence of the attribute and create it if needed. ----- Original Message ----- From: "Gilles Lenfant" <gilles@pilotsystems.net> To: <zope@zope.org> Sent: Tuesday, July 29, 2003 1:49 AM Subject: [Zope] Object
Hi,
I made a Product class with unpicklable attributes (compiled TALES expressions). Thus I got to name those _v_foo But for re-creating these attributes, I need to have a hook method called when the object is extracted from ZODB.
Is there such a hook method in Zope core classes ?
Thanks in advance.
--Gilles
_______________________________________________ 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 )
--__--__-- Pilot Systems http://www.pilotsystems.net 66, rue de Provence 75009 Paris Tel (direct): +33 1 44 53 25 93 Tel (standard): +33 1 44 53 05 55 Fax : +33 1 44 53 04 44 mailto:gilles@pilotsystems.net ----- Original Message ----- From: "Matt" <matt@inuan.com> To: "Gilles Lenfant" <gilles@pilotsystems.net>; <zope@zope.org> Sent: Tuesday, July 29, 2003 12:47 AM Subject: Re: [Zope] Object
You can define a __setstate__ method, but be aware that it has some restrictions, such as self not being acquisition wrapped. If you need those features of a fully instantiated published object, then attribute checks in a getter will allow you to test for the presence of the attribute and create it if needed.
Many thanks Matt... Where can I find the signature of that __setstate__ method ? Cheers --Gilles
The signature for __setstate__ can be found by evidence in zope/lib/python do a find . -name "*.py" | xargs grep -nH __setstate__ and you'll come up with many exmples. A search on Zope.org comes up with useful info too. regards Matt Gilles Lenfant wrote:
--__--__--
Pilot Systems http://www.pilotsystems.net
66, rue de Provence 75009 Paris Tel (direct): +33 1 44 53 25 93 Tel (standard): +33 1 44 53 05 55 Fax : +33 1 44 53 04 44
mailto:gilles@pilotsystems.net ----- Original Message ----- From: "Matt" <matt@inuan.com> To: "Gilles Lenfant" <gilles@pilotsystems.net>; <zope@zope.org> Sent: Tuesday, July 29, 2003 12:47 AM Subject: Re: [Zope] Object
You can define a __setstate__ method, but be aware that it has some restrictions, such as self not being acquisition wrapped. If you need
those
features of a fully instantiated published object, then attribute checks
in
a getter will allow you to test for the presence of the attribute and
create
it if needed.
Many thanks Matt...
Where can I find the signature of that __setstate__ method ?
Cheers
--Gilles
participants (4)
-
Andreas Jung -
Chris Withers -
Gilles Lenfant -
Matt