File writers now return NOT_MODIFIED to allow chaining things after them.
This commit is contained in:
@ -2,6 +2,7 @@ import csv
|
|||||||
|
|
||||||
from bonobo.config import Option
|
from bonobo.config import Option
|
||||||
from bonobo.config.processors import ContextProcessor, contextual
|
from bonobo.config.processors import ContextProcessor, contextual
|
||||||
|
from bonobo.constants import NOT_MODIFIED
|
||||||
from bonobo.util.objects import ValueHolder
|
from bonobo.util.objects import ValueHolder
|
||||||
from .file import FileHandler, FileReader, FileWriter
|
from .file import FileHandler, FileReader, FileWriter
|
||||||
|
|
||||||
@ -54,7 +55,7 @@ class CsvReader(CsvHandler, FileReader):
|
|||||||
|
|
||||||
for row in reader:
|
for row in reader:
|
||||||
if len(row) != field_count:
|
if len(row) != field_count:
|
||||||
raise ValueError('Got a line with %d fields, expecting %d.' % (len(row), field_count, ))
|
raise ValueError('Got a line with %d fields, expecting %d.' % (len(row), field_count,))
|
||||||
|
|
||||||
yield dict(zip(headers.value, row))
|
yield dict(zip(headers.value, row))
|
||||||
|
|
||||||
@ -72,3 +73,6 @@ class CsvWriter(CsvHandler, FileWriter):
|
|||||||
writer.writerow(headers.value)
|
writer.writerow(headers.value)
|
||||||
writer.writerow(row[header] for header in headers.value)
|
writer.writerow(row[header] for header in headers.value)
|
||||||
lineno.value += 1
|
lineno.value += 1
|
||||||
|
return NOT_MODIFIED
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
from bonobo.config import Option, Service
|
from bonobo.config import Option, Service
|
||||||
from bonobo.config.configurables import Configurable
|
from bonobo.config.configurables import Configurable
|
||||||
from bonobo.config.processors import ContextProcessor, contextual
|
from bonobo.config.processors import ContextProcessor, contextual
|
||||||
|
from bonobo.constants import NOT_MODIFIED
|
||||||
from bonobo.util.objects import ValueHolder
|
from bonobo.util.objects import ValueHolder
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
@ -94,6 +95,7 @@ class FileWriter(Writer):
|
|||||||
"""
|
"""
|
||||||
self._write_line(file, (self.eol if lineno.value else '') + row)
|
self._write_line(file, (self.eol if lineno.value else '') + row)
|
||||||
lineno.value += 1
|
lineno.value += 1
|
||||||
|
return NOT_MODIFIED
|
||||||
|
|
||||||
def _write_line(self, file, line):
|
def _write_line(self, file, line):
|
||||||
return file.write(line)
|
return file.write(line)
|
||||||
|
|||||||
Reference in New Issue
Block a user