diff roundup/rcsv.py @ 1862:0afdf96ea9d7

Add a wrapper around the two different reader() functions... which removes all empty lines, as both csv parsers barf on them [SF#821364].
author Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
date Fri, 24 Oct 2003 16:29:17 +0000
parents fdaa0b751355
children fc52d57c6c3e
line wrap: on
line diff
--- a/roundup/rcsv.py	Fri Oct 24 15:51:43 2003 +0000
+++ b/roundup/rcsv.py	Fri Oct 24 16:29:17 2003 +0000
@@ -5,6 +5,7 @@
 """
 
 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 @@
 try:
     import csv
     try:
-        reader = csv.reader
+        _reader = csv.reader
         writer = csv.writer
         excel = csv.excel
         error = ''
@@ -25,7 +26,7 @@
             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 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')

Roundup Issue Tracker: http://roundup-tracker.org/