fix unicode encoding of unicode strings, add delimeter option in CSVSource

This commit is contained in:
Jeremy Carbaugh 2009-07-29 16:51:16 -04:00
parent 2e1480d778
commit 20a7beebab
2 changed files with 4 additions and 2 deletions

View File

@ -360,6 +360,8 @@ class UnicodeFilter(Filter):
for key, value in record.iteritems(): for key, value in record.iteritems():
if isinstance(value, str): if isinstance(value, str):
record[key] = unicode(value, self._encoding, self._errors) record[key] = unicode(value, self._encoding, self._errors)
elif isinstance(value, unicode):
record[key] = value.encode(self._encoding, self._errors)
return record return record
########################### ###########################

View File

@ -22,9 +22,9 @@ class CSVSource(object):
ignoring the first row (presumed to be column names). ignoring the first row (presumed to be column names).
""" """
def __init__(self, csvfile, fieldnames=None, skiprows=0): def __init__(self, csvfile, fieldnames=None, skiprows=0, delimiter=','):
import csv import csv
self._dictreader = csv.DictReader(csvfile, fieldnames) self._dictreader = csv.DictReader(csvfile, fieldnames, delimiter=delimiter)
for _ in xrange(skiprows): for _ in xrange(skiprows):
self._dictreader.next() self._dictreader.next()