[mod_python] psp module

Wouter van Marle wouter at squirrel-systems.com
Wed May 18 21:47:52 EDT 2005


On Wed, 2005-05-18 at 21:12 -0400, Graham Dumpleton wrote:

> Wouter van Marle wrote ..
> > Hi all,
> > 
> > Is there a way to catch the html code as produced by the psp module?
> > 
> > I mean: normally one does something like:
> > page = psp.PSP(req,  "template.psp")
> > page.run({"spam": 1, "eggs": 5})
> > and the page is converted to html, and displayed in the browser.
> > 
> > Now is it possible to catch this html code in a string, instead of
> > sending it to the browser? This as I'd like to use the psp templating
> > for creating an e-mail body.
> 
> At first glance there seems to be no feature to do it. What you might
> try (I haven't), is that presuming that all output is generated through
> calls to req.write(), is to substitute the "req" object with a wrapper
> class that provides its own req.write() which is actually the write()
> method on a StringIO object.



Mmm... yeah should be something like that... well as I mainly use it for
actually building web pages in the same script, I'll just stick to
normal mails, or use some other method.

Do the developers accept feature requests? I have one.

Wouter.




> class Wrapper:
> 
>   def __init__(self,req,write):
>     self.__req = req
>     self.write = write
> 
>   def __getattr__(self,name):
>     return getattr(self,__req,name)
> 
> s = StringIO.StringIO()
> 
> page = psp.PSP(Wrapper(req,s.write),  "template.psp")
> page.run({"spam": 1, "eggs": 5})
> 
> req.log_error(s.getvalue())
> 
> If you were also stashing stuff in "req" from the PSP page, would also
> need a __setattr__() method in the wrapper.
> 
> Graham
>   
> 
> 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mm_cfg_has_not_been_edited_to_set_host_domains/pipermail/mod_python/attachments/20050519/9610608a/attachment.html


More information about the Mod_python mailing list