Georg Brandl committed db20c81

Fix force_decode() to work on Python 3.

Comments (0)

Files changed (2)


         new_sections = []
         for section in sections:
             if not isinstance(section, unicode):
-                # XXX is this really necessary?
                 new_sections.append(force_decode(section, None))
         return True
     def write_toc(self, node, indentlevel=4):
+        # XXX this should return a Unicode string, not a bytestring
         parts = []
         if self.isdocnode(node):
             refnode = node.children[0][0]
             link = refnode['refuri']
-            title = htmlescape(refnode.astext()).replace('"','"')
-            item = '<section title="%(title)s" ref="%(ref)s">' % {
-                                                                'title': title,
-                                                                'ref': link}
+            title = htmlescape(refnode.astext()).replace('"', '&quot;')
+            item = '<section title="%(title)s" ref="%(ref)s">' % \
+                {'title': title, 'ref': link}
             parts.append(' '*4*indentlevel + item)
             for subnode in node.children[1]:
                 parts.extend(self.write_toc(subnode, indentlevel+1))


 import sphinx
 from sphinx.errors import PycodeError
+from sphinx.util.pycompat import bytes
 # import other utilities; partly for backwards compatibility, so don't
 # prune unused ones indiscriminately
 def force_decode(string, encoding):
     """Forcibly get a unicode string out of a bytestring."""
-    if isinstance(string, str):
+    if isinstance(string, bytes):
         if encoding:
             string = string.decode(encoding)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.