💚 limit the UnicodeWriter to python 2 only, #44

This commit is contained in:
chfw 2017-11-10 17:22:14 +00:00
parent c5656ac5a8
commit 2c539ecf1f
2 changed files with 11 additions and 8 deletions

View File

@ -35,8 +35,7 @@ class UnicodeWriter(object):
for s in row])
# Fetch UTF-8 output from the queue ...
data = self.queue.getvalue()
if compact.PY2:
data = data.decode("utf-8")
data = data.decode("utf-8")
# ... and reencode it into the target encoding
data = self.encoder.encode(data)
# write to the target stream

View File

@ -9,7 +9,7 @@
"""
import zipfile
from pyexcel_io._compact import StringIO
from pyexcel_io._compact import StringIO, PY2
from pyexcel_io.book import BookWriter
from pyexcel_io.constants import DEFAULT_SHEET_NAME, FILE_FORMAT_CSVZ
@ -25,11 +25,15 @@ class CSVZipSheetWriter(CSVSheetWriter):
def set_sheet_name(self, name):
self.content = StringIO()
self.writer = UnicodeWriter(
self.content,
encoding=self._encoding,
**self._keywords
)
if PY2:
self.writer = UnicodeWriter(
self.content,
encoding=self._encoding,
**self._keywords
)
else:
import csv
self.writer = csv.writer(self.content, **self._keywords)
def close(self):
file_name = "%s.%s" % (self._native_sheet, self.file_extension)