[py3] Use "utf-8" as input encoding for docutils in rest extension 3.26
authorDenis Laxalde <denis.laxalde@logilab.fr>
Thu, 28 Jun 2018 12:19:16 +0200
branch3.26
changeset 12337 04ff0d3ef1d3
parent 12336 90ff36da4c8e
child 12338 b5533de552c4
child 12339 76d7b0aa94d2
[py3] Use "utf-8" as input encoding for docutils in rest extension Docutils says that "unicode" is an unknown encoding on Python3. Not sure where "unicode" as an encoding comes (it's there since showtime) but "utf-8" seems more appropriate. From now on, rendering of CubicWeb's rst directive (e.g. ..winclude) works on Python 3. Accordingly, we extend wdoc's test to demonstrate this. For this we need to install docutils in tox's web environment.
cubicweb/ext/rest.py
cubicweb/web/test/unittest_views_wdoc.py
requirements/test-web.txt
--- a/cubicweb/ext/rest.py	Thu Jun 28 11:19:14 2018 +0200
+++ b/cubicweb/ext/rest.py	Thu Jun 28 12:19:16 2018 +0200
@@ -404,7 +404,7 @@
     """
     req = context._cw
     if isinstance(data, text_type):
-        encoding = 'unicode'
+        encoding = 'utf-8'
         # remove unprintable characters unauthorized in xml
         data = data.translate(ESC_UCAR_TABLE)
     else:
--- a/cubicweb/web/test/unittest_views_wdoc.py	Thu Jun 28 11:19:14 2018 +0200
+++ b/cubicweb/web/test/unittest_views_wdoc.py	Thu Jun 28 12:19:16 2018 +0200
@@ -7,6 +7,9 @@
         with self.admin_access.web_request(fid='main') as req:
             page = req.view('wdoc')
         self.assertIn(u'Site documentation', page)
+        # This part is renderend through rst extension (..winclude directive).
+        self.assertIn(u'This web application is based on the CubicWeb knowledge management system',
+                      page)
 
 
 if __name__ == '__main__':
--- a/requirements/test-web.txt	Thu Jun 28 11:19:14 2018 +0200
+++ b/requirements/test-web.txt	Thu Jun 28 12:19:16 2018 +0200
@@ -1,3 +1,4 @@
+docutils
 Twisted < 16.0.0
 requests
 webtest