Simple framework for filtering data
A framework for filtering a stream of data. Write an object providing a filter(...) method and plug it into a Filter component.
Filters any non-strings from a stream of data:
class StringFilter(object): def filter(self, input): if type(input) == type(""): return input else: return None # indicates nothing to be output myfilter = Filter(filter = StringFilter).activate()
Initialize a Filter component, providing an object with a filter(...) method.
The method should take a single argument - the data to be filtered. It should return the result of the filtering/processing. If that result is None then the component outputs nothing, otherwise it outputs whatever the value is that was returned.
Data received on the component's "inbox" inbox is passed to the filter(...) method of the object you provided. The result is output on the "outbox" outbox.
If a producerFinished message is received on the "control" inbox then it is sent on out of the "signal" outbox. The component will then terminate.
However, before terminating it will repeatedly call your object's filter(...) method, passing it an empty string ("") until the result returned is None. If not None, then whatever value the filter(...) method returned is output. This is to give your object a chance to flush any data it may have been buffering.
Irrespective of whether your filtering object buffers any data from one call to the next, you must ensure that (eventually) calling it with an empty string ("") will result in None being returned.
Filter([filter]) -> new Filter component.
Component that can modify and filter data passing through it. Plug your own 'filter' into it.
Methods defined here
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Flush any data remaining in the filter before shutting down.
Main loop body.
Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!
Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.
-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT
This is an ongoing community based development site. As a result the contents of this page is the opinions of the contributors of the pages involved not the organisations involved. Specificially, this page may contain personal views which are not the views of the BBC. (the site is powered by a wiki engine)
(C) Copyright 2008 Kamaelia Contributors, including the British Broadcasting Corporation, All Rights Reserved.