From 7498afef504370c7c406d8cee501a01455de7507 Mon Sep 17 00:00:00 2001 From: jlgijsbers Date: Fri, 24 Oct 2003 16:29:17 +0000 Subject: [PATCH] Add a wrapper around the two different reader() functions, which removes all empty lines, as both csv parsers barf on them (bug #821364). git-svn-id: http://svn.roundup-tracker.org/svnroot/roundup/trunk@1931 57a73879-2fb5-44c3-a270-3262357dd7e2 --- roundup/rcsv.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/roundup/rcsv.py b/roundup/rcsv.py index da6a0a6..8957e35 100644 --- a/roundup/rcsv.py +++ b/roundup/rcsv.py @@ -5,6 +5,7 @@ needed by Roundup using the Python 2.3 csv module. """ from roundup.i18n import _ +from cStringIO import StringIO error = """Sorry, you need a module compatible with the csv module. Either upgrade your Python to 2.3 or later, or get and install the csv module from: @@ -15,7 +16,7 @@ These two csv modules are different but Roundup can use either. try: import csv try: - reader = csv.reader + _reader = csv.reader writer = csv.writer excel = csv.excel error = '' @@ -25,7 +26,7 @@ try: pass if hasattr(csv, 'parser'): error = '' - def reader(fileobj, dialect=excel): + def _reader(fileobj, dialect=excel): # note real readers take an iterable but 2.1 doesn't # support iterable access to file objects. result = [] @@ -63,6 +64,9 @@ class colon_separated(excel): class comma_separated(excel): delimiter = ',' +def reader(fileobject, dialect=excel): + csv_lines = [line for line in fileobject.readlines() if line.strip()] + return _reader(StringIO(''.join(csv_lines)), dialect) if __name__ == "__main__": f=open('testme.txt', 'r') -- 2.30.2