[mod_python] Capturing PSP output

Nicolas Lehuen nicolas.lehuen at gmail.com
Wed Jun 1 04:03:49 EDT 2005


What about modifying the PSP generator code so that it takes a new
optional "write" parameter, which is a callable object that will be
used to write the result ? If write is not defined, then the code will
use req.write.

Regards,

Nicolas

2005/6/1, Graham Dumpleton <grahamd at dscpl.com.au>:
> 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