[mod_python] Output Filters Redeaux

Nick nick at dd.revealed.net
Mon Apr 17 18:17:27 EDT 2006


Deron Meranda wrote:
> On 4/17/06, Nick <nick at dd.revealed.net> wrote:
>> The iterator would stop when None was read, so that's implicit.  Again, this
>> idea assumes a producer/consumer model rather than the repeated calling
>> model that is supported now.  And that, of course, implies some kind of
>> thread or fork and communication through a pipe or some other form of IPC,
>> unless there's some aspect of the apache API that I'm not aware of (which is
>> highly possible :)
> 
> Not sure why you're thinking about threads and IPC?

Mostly because a filter is called multiple times by apache, as new
information is available to be read.  As I understand the apache API, your
filter gets called the first time, ctx is NULL signaling the start of the
filtering, and you read buckets until you run out of input, then the handler
returns, waiting to be called again.  Apache will call the filter over and
over for the request until a read reaches the end of the BB stream, at which
point this will be the last time the filter is called.

> Anyway creating a generator-wrapper is the quickest way.  But you
> could modify the filter class so it acts like an iterator pretty easy.

That won't work in this case, because you can read in some stuff, then get
interrupted, then get called again to read in more stuff.  I don't think
there's a real advantage to making the filter object an iterator as the
handler currently works.

> And as Graham pointed out, doing the replace '\r\n' as you're
> doing it is quite fragile.  It will break when you least expect it to.

I guess that part is addressed to Lee :)

Nick


More information about the Mod_python mailing list