6618: Export CSV crashes gramps 4.0 beta

svn: r21998
This commit is contained in:
Benny Malengier 2013-04-15 11:01:08 +00:00
parent 83fb5d353d
commit 86686c764b
2 changed files with 13 additions and 6 deletions

View File

@ -50,7 +50,7 @@ class CSVTab(TabbedDoc):
else:
self.filename = filename
self.f = open(self.filename, "wb")
self.f = open(self.filename, "w")
self.writer = csv.writer(self.f)
def close(self):

View File

@ -154,15 +154,22 @@ class UnicodeWriter(object):
self.encoder = codecs.getencoder(encoding)
def writerow(self, row):
self.writer.writerow([s.encode('utf-8') for s in row])
# Fetch UTF-8 output from the queue ...
data = self.queue.getvalue()
data = data.decode('utf-8')
if sys.version_info[0] < 3:
self.writer.writerow([s.encode('utf-8') for s in row])
# Fetch UTF-8 output from the queue ...
data = self.queue.getvalue()
data = data.decode('utf-8')
else:
self.writer.writerow(row)
data = self.queue.getvalue()
#in python3, StringIO self.queue returns unicode!
#data now contains the csv data in unicode
# ... and reencode it into the target encoding
data, length = self.encoder(data)
# write to the target stream
self.stream.write(data)
# empty queue
# empty queue, go to start position, then truncate
self.queue.seek(0)
self.queue.truncate(0)
def writerows(self, rows):