[mod_python] Capturing PSP output

Graham Dumpleton grahamd at dscpl.com.au
Mon May 30 18:37:30 EDT 2005


On 31/05/2005, at 2:19 AM, Joshua Ginsberg wrote:

> Hello --
>
> I'm trying to do something a little unorthodox... I didn't know if 
> anybody had tried it before... Within a PSP page, I want to run 
> another PSP page and capture the output to a string.
>
> To do a little testing, I wrote the following PSP page:
>
> <%
>
> def sAppend(self, thestring):
>     if '__s__' not in dir(self):
>         self.__s__ = ''
>     self.__s__ += str(thestring)
>
> oldReqWrite = req.write
>
> req.write = sAppend

This is a bit confusing. Your method accepts a "self" parameter as if 
it is a
method of a class when it isn't. Just because you replace an existing 
instance
method will not turn your one into one.

The result is that the string to be output is being passed as self and 
string
doesn't have a "__s__" member.

There are other problems with using "__s__" as well but rather than go 
into it,
you should just look at:

   http://www.modpython.org/pipermail/mod_python/2005-May/018134.html

That code could probably still be cleaned up a bit perhaps as certain 
things
don't need to be done, also not sure why other things are being done 
either.
If I get a chance later I'll see if I can come up with a more 
streamlined
version.

BTW, did you want to actually reference the original "req" object for 
any
data. The example referenced obviously doesn't allow this as it 
completely
replaces the "req" object with a StringIO object.

Graham



More information about the Mod_python mailing list