@@ -29,6 +29,9 @@ except:
2929if sys.version_info[0] == 3:
3030 unichr = chr
3131 unicode = str
32+ IS_PY2 = False
33+else:
34+ IS_PY2 = True
3235
3336logger = logger.getChild('utils')
3437
@@ -159,19 +162,20 @@ class UnicodeWriter:
159162 self.encoder = getincrementalencoder(encoding)()
160163
161164 def writerow(self, row):
162− unicode_row = []
163− for col in row:
164− if type(col) == str or type(col) == unicode:
165− unicode_row.append(col.encode('utf-8').strip())
166− else:
167− unicode_row.append(col)
168− self.writer.writerow([x.decode('utf-8') if hasattr(x, 'decode') else x for x in unicode_row])
165+ if IS_PY2:
166+ row = [s.encode("utf-8") if hasattr(s, 'encode') else s for s in row]
167+ self.writer.writerow(row)
169168 # Fetch UTF-8 output from the queue ...
170− data = self.queue.getvalue().strip('\x00')
169+ data = self.queue.getvalue()
170+ if IS_PY2:
171+ data = data.decode("utf-8")
171172 # ... and reencode it into the target encoding
172173 data = self.encoder.encode(data)
173174 # write to the target stream
174− self.stream.write(data.decode('utf-8'))
175+ if IS_PY2:
176+ self.stream.write(data)
177+ else:
178+ self.stream.write(data.decode("utf-8"))
175179 # empty queue
176180 self.queue.truncate(0)
177181