[gnue] r10110 - trunk/gnue-common/src/datasources/drivers/file
[email protected] Wed, 9 Dec 2009 16:01:12 -0600 (CST)
| Newsgroups | gmane.comp.cms.gnue.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: reinhard
Date: 2009-12-09 16:01:12 -0600 (Wed, 09 Dec 2009)
New Revision: 10110
Modified:
trunk/gnue-common/src/datasources/drivers/file/csvfile.py
Log:
Allow for non ASCII content in CSV files.
Modified: trunk/gnue-common/src/datasources/drivers/file/csvfile.py
===================================================================
--- trunk/gnue-common/src/datasources/drivers/file/csvfile.py 2009-12-09 21:36:38 UTC (rev 10109)
+++ trunk/gnue-common/src/datasources/drivers/file/csvfile.py 2009-12-09 22:01:12 UTC (rev 10110)
@@ -28,6 +28,7 @@
__all__ = ['Connection']
import csv
+import locale
from gnue.common.datasources import GSchema
from gnue.common.datasources.drivers.file import Base
@@ -82,6 +83,22 @@
"""
# ---------------------------------------------------------------------------
+ # Constructor
+ # ---------------------------------------------------------------------------
+
+ def __init__ (self, connections, name, parameters):
+
+ Base.Connection.__init__ (self, connections, name, parameters)
+
+ if parameters.has_key ("encoding"):
+ self.__encoding = parameters ['encoding']
+ else:
+ self.__encoding = locale.getlocale()[1]
+ if self.__encoding is None:
+ self.__encoding = 'ascii'
+
+
+ # ---------------------------------------------------------------------------
# Iterate through the list of field names
# ---------------------------------------------------------------------------
@@ -110,8 +127,9 @@
reader = csv.DictReader (f, fieldnames, dialect = dialect)
- # Make a real list of dictionaries
- return [row for row in reader]
+ # Make a real list of dictionaries and convert to unicode.
+ return [dict( [(k, unicode(v, self.__encoding, errors='replace')) \
+ for (k, v) in row.iteritems()]) for row in reader]
# ---------------------------------------------------------------------------