File-like filter pattern?

Erik Max Francis max at alcyone.com
Wed Dec 18 19:53:40 EST 2002


Oren Tirosh wrote:

> Your filters are of the "push" type: a data source pushes data to the
> first filter which feeds it to the next filter, until it reaches the
> destinatio.
> 
> Another approach to implementing filter chains is "pull" filters where
> the
> sink pulls data from the last filter in the chain, which reads from
> the
> filter above it and eventually reads data from a source.

That's right.  I should have mentioned that I was talking about push
filters, although obviously it was easy to recognize that from the
context.  The only reason I'm talking about push filters is because
that's the parsing model that EmPy already uses, so I'm already
constrained to it.

> These two approaches are more-or-less equivalent but they don't mix
> very
> well. You can switch from pull to push by writing a loop that reads
> data
> from an upstream chain and feeds it to a downstream chain, ...

Right, it would just be the logical reverse of what I was describing,
where the _end_ of the filter stream does a read, which does its
filtering after calling reads on its source/previous filter in the
chain, and so on.

> ... but
> switching
> from push to pull requires the use of threads.

Right, or at least a non-blocking file object.

-- 
 Erik Max Francis / max at alcyone.com / http://www.alcyone.com/max/
 __ San Jose, CA, USA / 37 20 N 121 53 W / &tSftDotIotE
/  \ God does not play dice with the universe.
\__/ Albert Einstein
    Alcyone Systems' Daily Planet / http://www.alcyone.com/planet.html
 A new, virtual planet, every day.



More information about the Python-list mailing list