August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)
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.
Keyword arguments:
Warning!
You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.
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