[dataio, rqlquery] Fix url quoting and encoding issues (2to3)
authorSimon Chabot <simon.chabot@logilab.fr>
Tue, 01 Oct 2019 10:00:23 +0200
changeset 565 53defbcde5a5
parent 564 46dbd714ff87
child 566 f6ba33f1779a
[dataio, rqlquery] Fix url quoting and encoding issues (2to3)
nazca/utils/dataio.py
test/test_dataio.py
--- a/nazca/utils/dataio.py	Tue Oct 01 09:45:12 2019 +0200
+++ b/nazca/utils/dataio.py	Tue Oct 01 10:00:23 2019 +0200
@@ -24,6 +24,7 @@
 from six import binary_type, string_types, iteritems
 from six.moves import xrange
 from six.moves.urllib.request import urlopen
+import urllib.parse
 
 from lxml import etree
 
@@ -88,9 +89,10 @@
         indexes = indexes or []
         filehandle = urlopen('%(host)s/view?'
                              'rql=%(rql)s&vid=csvexport'
-                             % {'rql': rql, 'host': host})
+                             % {'rql': urllib.parse.quote(rql), 'host': host})
         filehandle.readline()  # Skip the first line
-        return parsefile(filehandle, delimiter=';', indexes=indexes,
+        lines = (line.decode('utf-8') for line in filehandle)
+        return parsefile(lines, delimiter=';', indexes=indexes,
                          formatopt=formatopt, autocast_data=autocast_data)
     else:
         # By appid
--- a/test/test_dataio.py	Tue Oct 01 09:45:12 2019 +0200
+++ b/test/test_dataio.py	Tue Oct 01 10:00:23 2019 +0200
@@ -257,7 +257,7 @@
     def test_rqlquery(self):
         results = rqlquery('http://www.cubicweb.org',
                            'Any U LIMIT 1 WHERE X cwuri U, X name "apycot"')
-        self.assertEqual(results, [[u'http://www.cubicweb.org/1310453']])
+        self.assertEqual(results, [['http://www.cubicweb.org/1310453']])
 
 
 if __name__ == '__main__':