[py3] Open files in binary mode in dataimport
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 02 Oct 2019 14:17:57 +0200
changeset 3038 33ad61a9f699
parent 3037 12980f28dd32
child 3039 f14dfe93073a
[py3] Open files in binary mode in dataimport
cubicweb_seda/dataimport.py
--- a/cubicweb_seda/dataimport.py	Wed Oct 02 13:51:45 2019 +0200
+++ b/cubicweb_seda/dataimport.py	Wed Oct 02 14:17:57 2019 +0200
@@ -18,6 +18,7 @@
 
 from __future__ import print_function
 
+import io
 from itertools import count
 from os.path import abspath, dirname, join
 
@@ -110,7 +111,7 @@
 
 def lcsv_import(cnx, store, fname, scheme_uri, **kwargs):
     """Actually import LCSV data file."""
-    with open(fname) as stream:
+    with io.open(fname, 'rb') as stream:
         extentities = skos.lcsv_extentities(stream, scheme_uri, ';', 'utf-8')
         import_log = SimpleImportLog(fname)
         skos.store_skos_extentities(cnx, store, extentities, import_log,
@@ -124,7 +125,7 @@
     def uri_generator(val):
         return text_type(next(counter)) + val
 
-    with open(join(dirname(__file__), 'migration', 'data', fname)) as stream:
+    with io.open(join(dirname(__file__), 'migration', 'data', fname), 'rb') as stream:
         lcsv2rdf = lcsv.LCSV2RDF(stream, separator, 'utf-8',
                                  # XXX drop once skos is released
                                  uri_generator=uri_generator, uri_cls=text_type)