[mod_python] Re: Speaking of Output Filters....

Daniel Nogradi nogradi at gmail.com
Tue Apr 11 04:26:49 EDT 2006

> > 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.

Indeed I ran into the same problem with my first filter, but this
article helped a lot in clarifying how bucket brigades work which I
think is the main thing to understand for writing a proper
input/output filter:


This is on mod_perl but the things about buckets in general are
explained quite well.

More information about the Mod_python mailing list