[mod_python] Capturing PSP output

Graham Dumpleton grahamd at dscpl.com.au
Wed Jun 1 02:50:53 EDT 2005


Graham Dumpleton wrote ..
> > Another method could be to use a delegating request object, something
> like
> > :
> > 
> > class FakeRequest(object):
> >     def __init__(self,req):
> >         self.req = req
> >         self.buffer = StringIO()
> > 
> >     def write(self,string,flush=1):
> >         self.buffer.write(string)
> > 
> >     def __getattr__(self,name):
> >         return getattr(self.req,name)
> 
> In some ways this is nicer, but also has problems in that it cannot entirely
> replace the original request object because of type checking within the
> C
> code in mod_python.
> 
> For example, if using the fake request object and you wrote something like:
> 
>   req.register_cleanup(req,somefunc)
> 
> it will fail. This is because req.register_cleanup() is implemented in
> C code
> and explicitly checks to see if the "req" argument matches the the type
> of
> the C implemented <requestobject>. The check will fail and an exception
> is raised.

Whoops, wrong method. I mean't:

  req.server.register_cleanup(req,somefunc)

The req.register_cleanup() method doesn't take a request object as first
argument, but cleanup handlers for whole server registered by using
req.server.register_cleanup() do.

:-(

Graham


More information about the Mod_python mailing list