Less strict CSV processing, to allow dirty input.

This commit is contained in:
Romain Dorgueil
2017-11-12 10:36:07 +01:00
parent c2f17296f6
commit 0b3694142b

View File

@ -1,4 +1,5 @@
import csv
import warnings
from bonobo.config import Option
from bonobo.config.options import RemovedOption
@ -62,7 +63,7 @@ class CsvReader(FileReader, CsvHandler):
for row in reader:
if len(row) != field_count:
raise ValueError('Got a line with %d fields, expecting %d.' % (
warnings.warn('Got a line with %d fields, expecting %d.' % (
len(row),
field_count,
))
@ -81,6 +82,6 @@ class CsvWriter(FileWriter, CsvHandler):
if not lineno:
headers.set(headers.value or row.keys())
writer.writerow(headers.get())
writer.writerow(row[header] for header in headers.get())
writer.writerow(row.get(header, '') for header in headers.get())
lineno += 1
return NOT_MODIFIED