From b607441494326d37c26c1daea5ebd24a8c70aca3 Mon Sep 17 00:00:00 2001 From: James Turk Date: Sat, 20 Feb 2010 13:59:36 -0500 Subject: [PATCH] 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) --- saucebrush/__init__.py | 2 +- saucebrush/filters.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/saucebrush/__init__.py b/saucebrush/__init__.py index 648ec78..767766d 100644 --- a/saucebrush/__init__.py +++ b/saucebrush/__init__.py @@ -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: diff --git a/saucebrush/filters.py b/saucebrush/filters.py index a63a59d..77b5db2 100644 --- a/saucebrush/filters.py +++ b/saucebrush/filters.py @@ -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