6618: Export CSV crashes gramps 4.0 beta
svn: r21998
This commit is contained in:
parent
83fb5d353d
commit
86686c764b
@ -50,7 +50,7 @@ class CSVTab(TabbedDoc):
|
|||||||
else:
|
else:
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
|
|
||||||
self.f = open(self.filename, "wb")
|
self.f = open(self.filename, "w")
|
||||||
self.writer = csv.writer(self.f)
|
self.writer = csv.writer(self.f)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
|
@ -154,15 +154,22 @@ class UnicodeWriter(object):
|
|||||||
self.encoder = codecs.getencoder(encoding)
|
self.encoder = codecs.getencoder(encoding)
|
||||||
|
|
||||||
def writerow(self, row):
|
def writerow(self, row):
|
||||||
self.writer.writerow([s.encode('utf-8') for s in row])
|
if sys.version_info[0] < 3:
|
||||||
# Fetch UTF-8 output from the queue ...
|
self.writer.writerow([s.encode('utf-8') for s in row])
|
||||||
data = self.queue.getvalue()
|
# Fetch UTF-8 output from the queue ...
|
||||||
data = data.decode('utf-8')
|
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
|
# ... and reencode it into the target encoding
|
||||||
data, length = self.encoder(data)
|
data, length = self.encoder(data)
|
||||||
# write to the target stream
|
# write to the target stream
|
||||||
self.stream.write(data)
|
self.stream.write(data)
|
||||||
# empty queue
|
# empty queue, go to start position, then truncate
|
||||||
|
self.queue.seek(0)
|
||||||
self.queue.truncate(0)
|
self.queue.truncate(0)
|
||||||
|
|
||||||
def writerows(self, rows):
|
def writerows(self, rows):
|
||||||
|
Loading…
Reference in New Issue
Block a user