[py3] Open rst file in text mode in wdoc view 3.26
authorDenis Laxalde <denis.laxalde@logilab.fr>
Thu, 28 Jun 2018 10:06:26 +0200
branch3.26
changeset 12334 4c0f7ef3145c
parent 12333 1693730548ef
child 12335 ec2ab8dc93a2
[py3] Open rst file in text mode in wdoc view Otherwise, UStringIO complains that it receives bytes.
cubicweb/web/views/wdoc.py
--- a/cubicweb/web/views/wdoc.py	Thu Jun 28 11:11:10 2018 +0200
+++ b/cubicweb/web/views/wdoc.py	Thu Jun 28 10:06:26 2018 +0200
@@ -21,6 +21,7 @@
 """
 
 
+import io
 from itertools import chain
 from os.path import join
 from xml.etree.ElementTree import parse
@@ -132,8 +133,8 @@
             self.navigation_links(node)
             self.w(u'<div class="hr"></div>')
             self.w(u'<h1>%s</h1>' % (title_for_lang(node, self._cw.lang)))
-        data = open(join(resourcedir, rid)).read()
-        self.w(rest_publish(self, data))
+        with io.open(join(resourcedir, rid)) as f:
+            self.w(rest_publish(self, f.read()))
         if node is not None:
             self.subsections_links(node)
             self.w(u'<div class="hr"></div>')
@@ -200,7 +201,8 @@
                 break
         else:
             raise NotFound
-        self.w(open(join(resourcedir, rid)).read())
+        with io.open(join(resourcedir, rid)) as f:
+            self.w(f.read())
 
 
 class HelpAction(action.Action):