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

Graham Dumpleton grahamd at dscpl.com.au
Tue Apr 11 06:48:56 EDT 2006

On 11/04/2006, at 6:26 PM, Daniel Nogradi wrote:

>>> 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:
> http://perl.apache.org/docs/2.0/user/handlers/filters.html
> This is on mod_perl but the things about buckets in general are
> explained quite well.

Another good jumping off point for background information is:


Obviously mod_python simplifies it a lot by hiding the bucket
brigade, but still good stuff.


More information about the Mod_python mailing list