@@ -29,6 +29,9 @@ except:
29if sys.version_info[0] == 3:
29if sys.version_info[0] == 3:
30 unichr = chr
30 unichr = chr
31 unicode = str
31 unicode = str
33logger = logger.getChild('utils')
36logger = logger.getChild('utils')
@@ -159,19 +162,20 @@ class UnicodeWriter:
159 self.encoder = getincrementalencoder(encoding)()
162 self.encoder = getincrementalencoder(encoding)()
161 def writerow(self, row):
164 def writerow(self, row):
162− unicode_row = []
165+ if IS_PY2:
163− for col in row:
166+ row = [s.encode("utf-8") if hasattr(s, 'encode') else s for s in row]
164− if type(col) == str or type(col) == unicode:
165− unicode_row.append(col.encode('utf-8').strip())
167− unicode_row.append(col)
168− self.writer.writerow([x.decode('utf-8') if hasattr(x, 'decode') else x for x in unicode_row])
167+ self.writer.writerow(row)
169 # Fetch UTF-8 output from the queue ...
168 # Fetch UTF-8 output from the queue ...
170− data = self.queue.getvalue().strip('\x00')
169+ data = self.queue.getvalue()
171+ data = data.decode("utf-8")
171 # ... and reencode it into the target encoding
172 # ... and reencode it into the target encoding
172 data = self.encoder.encode(data)
173 data = self.encoder.encode(data)
173 # write to the target stream
174 # write to the target stream
176+ self.stream.write(data)
174− self.stream.write(data.decode('utf-8'))
178+ self.stream.write(data.decode("utf-8"))
175 # empty queue
179 # empty queue
176 self.queue.truncate(0)
180 self.queue.truncate(0)