6618: Export CSV crashes gramps 4.0 beta
svn: r21999
This commit is contained in:
parent
77adb230c5
commit
16cfc2af23
@ -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):
|
||||
|
@ -154,15 +154,22 @@ class UnicodeWriter(object):
|
||||
self.encoder = codecs.getencoder(encoding)
|
||||
|
||||
def writerow(self, row):
|
||||
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):
|
||||
|
Loading…
Reference in New Issue
Block a user