[Zope-dev] __after_publishing_traverse__
Ivo van der Wijk
ivo@amaze.nl
Mon, 15 Apr 2002 17:01:54 +0200
On Mon, Apr 15, 2002 at 09:39:47AM -0600, Casey Duncan wrote:
> The request object has a hold area which keeps objects alive as long as
> the request lives. Although I have not tried it, you might be able to
> add an object to this hold area using __bobo_traverse__ defined on B.
>
> This object's class would need to have a destructor method (__del__)
> defined so that it can do something when the request is over and the
> response has presumably been written.
>
> you could code that something like this:
>
> In b's class:
>
> class b:
> ...
> def __bobo_traverse__(self, name):
> self.REQUEST._hold(ResponseChecker(self.REQUEST.RESPONSE))
>
> class ResponseChecker:
> def __init__(self, response):
> self.response = response
>
> def __del__(self):
> ...do something with self.response...
>
> Like I said, I've never tried this, but you never know, it might work.
> If not, another option would be to have b use __bobo_traverse__ to
> dynamically add a destructor to the RESPONSE object (it doesn't already
> have one AFAIK). Like this:
>
This indeed does work. The only difference is that I'm installing the hook
in __before_publishing_traverse__, so I don't have to do any traversal
myself.
I find it a scary solution though (though not as scary as monkeypatching
__del__), so I'm not 100% sure if I will use this code, or perhaps I'll
make it very optional (basically, thanks to this nice hack, QuotaFolder can
do traffic accounting as well :)
Cheers,
Ivo
--
Drs. I.R. van der Wijk -=-
Brouwersgracht 132 Amaze Internet Services V.O.F.
1013 HA Amsterdam, NL -=-
Tel: +31-20-4688336 Linux/Web/Zope/SQL/MMBase
Fax: +31-20-4688337 Network Solutions
Web: http://www.amaze.nl/ Consultancy
Email: ivo@amaze.nl -=-