[mod_python] Speaking of Output Filters....

Graham Dumpleton grahamd at dscpl.com.au
Mon Apr 10 18:34:20 EDT 2006

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.


More information about the Mod_python mailing list