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_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):
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user