🐛 fix python 3 bug with http source. fix https://github.com/pyexcel/pyexcel/issues/185
This commit is contained in:
parent
6f2660f032
commit
57b1b49b0a
|
@ -231,6 +231,12 @@ class BookWriter(RWInterface):
|
|||
|
||||
def _convert_content_to_stream(file_content, file_type):
|
||||
stream = manager.get_io(file_type)
|
||||
if not PY2:
|
||||
target_content_type = manager.get_io_type(file_type)
|
||||
if target_content_type == 'bytes' and not isinstance(file_content, bytes):
|
||||
file_content = file_content.encode('utf-8')
|
||||
elif target_content_type == 'string' and isinstance(file_content, bytes):
|
||||
file_content = file_content.decode('utf-8')
|
||||
stream.write(file_content)
|
||||
stream.seek(0)
|
||||
return stream
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
from nose.tools import raises
|
||||
from pyexcel_io.book import RWInterface, BookReader, BookWriter
|
||||
from pyexcel_io.book import RWInterface, BookReader, BookWriter, _convert_content_to_stream
|
||||
from pyexcel_io._compact import PY2, StringIO, BytesIO
|
||||
from nose import SkipTest
|
||||
|
||||
|
||||
@raises(NotImplementedError)
|
||||
|
@ -30,3 +32,21 @@ def test_book_reader_open_stream():
|
|||
def test_book_writer():
|
||||
writer = BookWriter()
|
||||
writer.open_stream("a string")
|
||||
|
||||
|
||||
def test_convert_to_bytes_stream():
|
||||
if PY2:
|
||||
raise SkipTest('No need test in python 2')
|
||||
else:
|
||||
file_content = b'test'
|
||||
stream = _convert_content_to_stream(file_content, 'string')
|
||||
assert isinstance(stream, StringIO)
|
||||
|
||||
|
||||
def test_convert_to_string_stream():
|
||||
if PY2:
|
||||
raise SkipTest('No need test in python 2')
|
||||
else:
|
||||
file_content = 'test'
|
||||
stream = _convert_content_to_stream(file_content, 'bytes')
|
||||
assert isinstance(stream, BytesIO)
|
||||
|
|
Loading…
Reference in New Issue