HTML builder dump_inventory needs to use the config's encoding for entries

Anonymous avatarAnonymous created an issue

I don't know if this is the right fix for it, but I was getting errors with some documents that had German characters in titles and names with Python 2.6 on Mac OS X. This patch fixed it.

# Sphinx version: 1.0pre/c3a4ec6a4e32
# Docutils version: 0.6 release
# Jinja2 version: 2.2.1
Traceback (most recent call last):
  File "/Users/hobu/hg/sphinx/sphinx/cmdline.py", line 173, in main
    app.build(force_all, filenames)
  File "/Users/hobu/hg/sphinx/sphinx/application.py", line 205, in build
    self.builder.build_update()
  File "/Users/hobu/hg/sphinx/sphinx/builders/__init__.py", line 198, in build_update
    'out of date' % len(to_build))
  File "/Users/hobu/hg/sphinx/sphinx/builders/__init__.py", line 254, in build
    self.write(docnames, list(updated_docnames), method)
  File "/Users/hobu/hg/sphinx/sphinx/builders/__init__.py", line 293, in write
    self.write_doc(docname, doctree)
  File "/Users/hobu/hg/sphinx/sphinx/builders/html.py", line 407, in write_doc
    self.docwriter.write(doctree, destination)
  File "/Library/Python/2.6/site-packages/docutils-0.6-py2.6.egg/docutils/writers/__init__.py", line 76, in write
    self.translate()
  File "/Users/hobu/hg/sphinx/sphinx/writers/html.py", line 37, in translate
    self.document.walkabout(visitor)
  File "/Library/Python/2.6/site-packages/docutils-0.6-py2.6.egg/docutils/nodes.py", line 173, in walkabout
    if child.walkabout(visitor):
  File "/Library/Python/2.6/site-packages/docutils-0.6-py2.6.egg/docutils/nodes.py", line 173, in walkabout
    if child.walkabout(visitor):
  File "/Library/Python/2.6/site-packages/docutils-0.6-py2.6.egg/docutils/nodes.py", line 186, in walkabout
    visitor.dispatch_departure(self)
  File "/Library/Python/2.6/site-packages/docutils-0.6-py2.6.egg/docutils/nodes.py", line 1617, in dispatch_departure
    return method(node)
  File "/Users/hobu/hg/sphinx/sphinx/writers/html.py", line 482, in depart_title
    _('Permalink to this headline'))
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 20: ordinal not in range(128)

diff -r f8acb3ce3fd3 sphinx/builders/html.py
--- a/sphinx/builders/html.py	Wed May 26 00:25:41 2010 +0200
+++ b/sphinx/builders/html.py	Wed May 26 10:51:32 2010 -0500
@@ -747,7 +747,12 @@
                     if anchor.endswith(name):
                         # this can shorten the inventory by as much as 25%
                         anchor = anchor[:-len(name)] + '$'
-                    uri = self.get_target_uri(docname) + '#' + anchor
+                    uri = self.get_target_uri(docname) + '#' + anchor 
+                    encoding = self.config.source_encoding
+                    uri = uri.encode(encoding)
+                    dispname = dispname.encode(encoding)
+                    name = name.encode(encoding)
+                    domainname = domainname.encode(encoding)
                     if dispname == name:
                         dispname = '-'
                     f.write(compressor.compress(

Comments (2)

  1. Log in to comment
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 ProjectModifiedEvent.java.
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.