filters are no longer callables

filters were originally callables, but with the addition of recipe
as a required parameter code no longer looks like

result = filter(filter2(filter3(data)))
--but instead--
result = filter3(filter3(filter3(data, recipe), recipe), recipe)

this looks cleaner when written like:
data2 = filter.attach(data, recipe)
data3 = filter.attach(data2, recipe1)
result = filter.attach(data3, recipe2)
This commit is contained in:
James Turk 2010-02-20 13:59:36 -05:00
parent c8991869ba
commit b607441494
2 changed files with 5 additions and 5 deletions

View File

@ -37,7 +37,7 @@ class Recipe(filters.Filter):
# connect datapath
data = source
for filter_ in filters:
data = filter_(data, recipe=self)
data = filter_.attach(data, recipe=self)
# actually run the data through (causes iterators to actually be called)
for record in data:

View File

@ -35,7 +35,7 @@ class Filter(object):
if recipe:
recipe.reject_record(record, message)
def __call__(self, source, recipe=None):
def attach(self, source, recipe=None):
self._recipe = recipe
for record in source:
result = self.process_record(record)
@ -51,7 +51,7 @@ class YieldFilter(Filter):
filter must derive from YieldFilter.
"""
def __call__(self, source, recipe=None):
def attach(self, source, recipe=None):
self._recipe = recipe
for record in source:
for result in self.process_record(record):
@ -286,10 +286,10 @@ class Splitter(Filter):
for filter_ in filters:
subrecord = filter_.process_record(subrecord)
# if a list or tuple, use __call__
# if a list or tuple, use attach
elif isinstance(subrecord, (list, tuple)):
for filter_ in filters:
subrecord = filter_(subrecord, recipe=self._recipe)
subrecord = filter_.attach(subrecord, recipe=self._recipe)
subrecord = [r for r in subrecord] # unchain generators
# place back from whence it came