Skip to content

Commit 910131b

Browse files
author
Johannes Gijsbers
committed
Add a wrapper around the two different reader() functions...
which removes all empty lines, as both csv parsers barf on them [SF#821364].
1 parent 31e73a4 commit 910131b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

roundup/rcsv.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
from roundup.i18n import _
8+
from cStringIO import StringIO
89
error = """Sorry, you need a module compatible with the csv module.
910
Either upgrade your Python to 2.3 or later, or get and install
1011
the csv module from:
@@ -15,7 +16,7 @@
1516
try:
1617
import csv
1718
try:
18-
reader = csv.reader
19+
_reader = csv.reader
1920
writer = csv.writer
2021
excel = csv.excel
2122
error = ''
@@ -25,7 +26,7 @@ class excel:
2526
pass
2627
if hasattr(csv, 'parser'):
2728
error = ''
28-
def reader(fileobj, dialect=excel):
29+
def _reader(fileobj, dialect=excel):
2930
# note real readers take an iterable but 2.1 doesn't
3031
# support iterable access to file objects.
3132
result = []
@@ -63,6 +64,9 @@ class colon_separated(excel):
6364
class comma_separated(excel):
6465
delimiter = ','
6566

67+
def reader(fileobject, dialect=excel):
68+
csv_lines = [line for line in fileobject.readlines() if line.strip()]
69+
return _reader(StringIO(''.join(csv_lines)), dialect)
6670

6771
if __name__ == "__main__":
6872
f=open('testme.txt', 'r')

0 commit comments

Comments
 (0)