handle switch from generator next() to __next__()
This commit is contained in:
parent
e5f1012e17
commit
8d512d7e07
@ -301,7 +301,11 @@ class FieldAdder(Filter):
|
|||||||
self._field_name = field_name
|
self._field_name = field_name
|
||||||
self._field_value = field_value
|
self._field_value = field_value
|
||||||
if hasattr(self._field_value, '__iter__'):
|
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
|
self._replace = replace
|
||||||
|
|
||||||
def process_record(self, record):
|
def process_record(self, record):
|
||||||
|
@ -59,13 +59,18 @@ class FixedWidthFileSource(object):
|
|||||||
def __iter__(self):
|
def __iter__(self):
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def next(self):
|
def __next__(self):
|
||||||
line = self._fwfile.next()
|
line = next(self._fwfile)
|
||||||
record = {}
|
record = {}
|
||||||
for name, range_ in self._fields_dict.items():
|
for name, range_ in self._fields_dict.items():
|
||||||
record[name] = line[range_[0]:range_[1]].rstrip(self._fillchars)
|
record[name] = line[range_[0]:range_[1]].rstrip(self._fillchars)
|
||||||
return record
|
return record
|
||||||
|
|
||||||
|
def next(self):
|
||||||
|
""" Keep Python 2 next() method that defers to __next__().
|
||||||
|
"""
|
||||||
|
return self.__next__()
|
||||||
|
|
||||||
|
|
||||||
class HtmlTableSource(object):
|
class HtmlTableSource(object):
|
||||||
""" Saucebrush source for reading data from an HTML table.
|
""" Saucebrush source for reading data from an HTML table.
|
||||||
|
@ -63,7 +63,8 @@ class FilterTestCase(unittest.TestCase):
|
|||||||
recipe = DummyRecipe()
|
recipe = DummyRecipe()
|
||||||
f = Doubler()
|
f = Doubler()
|
||||||
result = f.attach([1,2,3], recipe=recipe)
|
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')
|
f.reject_record('bad', 'this one was bad')
|
||||||
|
|
||||||
# ensure that the rejection propagated to the recipe
|
# ensure that the rejection propagated to the recipe
|
||||||
@ -202,7 +203,7 @@ class FilterTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
def test_field_keeper(self):
|
def test_field_keeper(self):
|
||||||
fk = FieldKeeper(['c'])
|
fk = FieldKeeper(['c'])
|
||||||
|
|
||||||
# check against expected results
|
# check against expected results
|
||||||
expected_data = [{'c':3}, {'c':5}, {'c':100}]
|
expected_data = [{'c':3}, {'c':5}, {'c':100}]
|
||||||
self.assert_filter_result(fk, expected_data)
|
self.assert_filter_result(fk, expected_data)
|
||||||
|
Loading…
Reference in New Issue
Block a user