| 38 | self.encoder = codecs.getincrementalencoder(encoding)() |
| 39 | |
| 40 | def writerow(self, row): |
| 41 | if six.PY2: |
| 42 | _row = [s.encode("utf-8") |
| 43 | if hasattr(s, "encode") |
| 44 | else s |
| 45 | for s in row] |
| 46 | else: |
| 47 | _row = row |
| 48 | self.writer.writerow(_row) |
| 49 | # Fetch UTF-8 output from the queue ... |
| 50 | data = self.queue.getvalue() |
| 51 | if six.PY2: |
| 52 | data = data.decode("utf-8") |
| 53 | # ... and reencode it into the target encoding |
| 54 | data = self.encoder.encode(data) |
| 55 | # write to the target stream |
| 56 | self.stream.write(data) |
| 57 | # empty queue |
| 58 | self.queue.truncate(0) |
| 59 | self.queue.seek(0) |
| 60 | |
| 61 | def writerows(self, rows): |
| 62 | for row in rows: |