diff --git a/saucebrush/filters.py b/saucebrush/filters.py index 2b9584b..bc1c7be 100644 --- a/saucebrush/filters.py +++ b/saucebrush/filters.py @@ -301,7 +301,11 @@ class FieldAdder(Filter): self._field_name = field_name self._field_value = field_value if hasattr(self._field_value, '__iter__'): - self._field_value = iter(self._field_value).next + value_iter = iter(self._field_value) + if hasattr(value_iter, "next"): + self._field_value = value_iter.next + else: + self._field_value = value_iter.__next__ self._replace = replace def process_record(self, record): diff --git a/saucebrush/sources.py b/saucebrush/sources.py index 06cf60b..c5c6554 100644 --- a/saucebrush/sources.py +++ b/saucebrush/sources.py @@ -59,13 +59,18 @@ class FixedWidthFileSource(object): def __iter__(self): return self - def next(self): - line = self._fwfile.next() + def __next__(self): + line = next(self._fwfile) record = {} for name, range_ in self._fields_dict.items(): record[name] = line[range_[0]:range_[1]].rstrip(self._fillchars) return record + def next(self): + """ Keep Python 2 next() method that defers to __next__(). + """ + return self.__next__() + class HtmlTableSource(object): """ Saucebrush source for reading data from an HTML table. diff --git a/saucebrush/tests/filters.py b/saucebrush/tests/filters.py index d0f3b85..c7e4dc7 100644 --- a/saucebrush/tests/filters.py +++ b/saucebrush/tests/filters.py @@ -63,7 +63,8 @@ class FilterTestCase(unittest.TestCase): recipe = DummyRecipe() f = Doubler() result = f.attach([1,2,3], recipe=recipe) - result.next() # next has to be called for attach to take effect + # next has to be called for attach to take effect + next(result) f.reject_record('bad', 'this one was bad') # ensure that the rejection propagated to the recipe @@ -202,7 +203,7 @@ class FilterTestCase(unittest.TestCase): def test_field_keeper(self): fk = FieldKeeper(['c']) - + # check against expected results expected_data = [{'c':3}, {'c':5}, {'c':100}] self.assert_filter_result(fk, expected_data)