[mod_python] Speaking of Output Filters....

Lee Brown administrator at leebrown.org
Tue Apr 11 07:30:42 EDT 2006


Greetings!

All good points which I hadn't considered.  The filters have worked very
well so far, though, mostly (I suspect) because I wrote these filters as a
means of merging and transforming content in lieu of using any content
handlers at all.  The content I'm trying to serve is all "quasi-dynamic,"
that is, the content changes, but only when a content author or some
back-end program decides to change it.  As far as the Apache server is
concerned, it all looks like static content.

I haven't tried serving up "War and Peace" as a single web page yet, but
I've tested my filters using what I'd call "unreasonably long" web pages
without any problems - so far.

I'll take a shot at reformulating my code and let you know how it turns out.
It may not even be necessary to accumulate the data in a buffer; if lxml is
using a push-parser it will accept the data piece-wise and all I'd need to
do is detect EOS before invoking the tranform.  

Best Regards,
Lee E. Brown
(administrator at leebrown.org)

-----Original Message-----
From: mod_python-bounces at modpython.org
[mailto:mod_python-bounces at modpython.org] On Behalf Of Graham Dumpleton
Sent: Monday, April 10, 2006 6:34 PM
To: Lee Brown
Cc: mod_python at modpython.org
Subject: Re: [mod_python] Speaking of Output Filters....

Lee Brown wrote ..
> Greetings!
> 
> I am probably remiss for not having shared this before now.  Here are 
> two output filters for mod_python that I have developed.
>
> ...
>
> def outputfilter (filter):
>     xmlstring = filter.read()
>     doc = lxml.etree.parse(StringIO(xmlstring))
>     doc.xinclude()
>     result = str(transformer(doc))
>     filter.write(result)
>     filter.close()

I suspect that these filters will not work in all situations. This is
because a filter can be called multiple times for a single request and
within one invocation, it is not guaranteed that filter.read() will return
all the data.

In short, your filter will only work when serving up static files and maybe
only files up to a certain size at that perhaps. It is not likely to work
where the XML is generated by a content handler.

This is why the prior posters filters would accumulate data in a list held
in request object until read() returned None and only then process data,
write it out and close the filter off.

Graham
_______________________________________________
Mod_python mailing list
Mod_python at modpython.org
http://mailman.modpython.org/mailman/listinfo/mod_python



More information about the Mod_python mailing list