Fix unicode support in CSV catalog output

This commit is contained in:
Kovid Goyal 2010-01-21 17:18:50 -07:00
parent d96910f3ea
commit 03c5a395f3

View File

@ -41,7 +41,7 @@ class CSV_XML(CatalogPlugin):
log = Log()
self.fmt = path_to_output.rpartition('.')[2]
if False and opts.verbose:
log("%s:run" % self.name)
log(" path_to_output: %s" % path_to_output)
@ -54,7 +54,7 @@ class CSV_XML(CatalogPlugin):
log(" opts:")
for key in keys:
log(" %s: %s" % (key, opts_dict[key]))
# Get the sorted, filtered database as a dictionary
data = self.search_sort_db(db, opts)
@ -69,7 +69,7 @@ class CSV_XML(CatalogPlugin):
outfile = open(path_to_output, 'w')
# Output the field headers
outfile.write('%s\n' % ','.join(fields))
outfile.write(u'%s\n' % u','.join(fields))
# Output the entry fields
for entry in data:
@ -80,15 +80,15 @@ class CSV_XML(CatalogPlugin):
item = ', '.join(item)
if x < len(fields) - 1:
if item is not None:
outstr += '"%s",' % str(item).replace('"','""')
outstr += u'"%s",' % unicode(item).replace('"','""')
else:
outstr += '"",'
else:
if item is not None:
outstr += '"%s"\n' % str(item).replace('"','""')
outstr += u'"%s"\n' % unicode(item).replace('"','""')
else:
outstr += '""\n'
outfile.write(outstr)
outfile.write(outstr.encode('utf-8'))
outfile.close()
elif self.fmt == 'xml':