added unicode support for TSV for pytjhon 2
This commit is contained in:
parent
9696733fd1
commit
5a7c35518b
|
@ -164,6 +164,12 @@ class TSV(TextFormat):
|
|||
TABLIB_MODULE = 'tablib.formats._tsv'
|
||||
CONTENT_TYPE = 'text/tab-separated-values'
|
||||
|
||||
def create_dataset(self, in_stream, **kwargs):
|
||||
if sys.version_info[0] < 3:
|
||||
# python 2.7 csv does not do unicode
|
||||
return super(TSV, self).create_dataset(in_stream.encode('utf-8'), **kwargs)
|
||||
return super(TSV, self).create_dataset(in_stream, **kwargs)
|
||||
|
||||
|
||||
class ODS(TextFormat):
|
||||
TABLIB_MODULE = 'tablib.formats._ods'
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
id name author_email
|
||||
1 Some bookš test@example.com
|
|
|
@ -74,3 +74,20 @@ class CSVTest(TestCase):
|
|||
with open(filename, self.format.get_read_mode()) as in_stream:
|
||||
data = force_text(in_stream.read())
|
||||
base_formats.CSV().create_dataset(data)
|
||||
|
||||
|
||||
class TSVTest(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.format = base_formats.CSV()
|
||||
|
||||
def test_import_unicode(self):
|
||||
# importing tsv UnicodeEncodeError
|
||||
filename = os.path.join(
|
||||
os.path.dirname(__file__),
|
||||
os.path.pardir,
|
||||
'exports',
|
||||
'books-unicode.tsv')
|
||||
with open(filename, self.format.get_read_mode()) as in_stream:
|
||||
data = force_text(in_stream.read())
|
||||
base_formats.CSV().create_dataset(data)
|
||||
|
|
Binary file not shown.
Loading…
Reference in New Issue