From 0d4c3a31b63e58602e469e65a164ddcfc1e4443e Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Wed, 26 May 2010 19:51:09 +0200 Subject: [PATCH] #426: Fix encoding issues when saving/loading intersphinx inventories. --- sphinx/builders/html.py | 11 +++++++---- sphinx/ext/intersphinx.py | 6 +++--- tests/root/markup.txt | 2 ++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index 94665dcf7..2b73885ee 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -738,7 +738,7 @@ class StandaloneHTMLBuilder(Builder): try: f.write('# Sphinx inventory version 2\n') f.write('# Project: %s\n' % self.config.project.encode('utf-8')) - f.write('# Version: %s\n' % self.config.version) + f.write('# Version: %s\n' % self.config.version.encode('utf-8')) f.write('# The remainder of this file is compressed using zlib.\n') compressor = zlib.compressobj(9) for domainname, domain in self.env.domains.iteritems(): @@ -749,10 +749,13 @@ class StandaloneHTMLBuilder(Builder): anchor = anchor[:-len(name)] + '$' uri = self.get_target_uri(docname) + '#' + anchor if dispname == name: - dispname = '-' + dispname = u'-' f.write(compressor.compress( - '%s %s:%s %s %s %s\n' % (name, domainname, type, prio, - uri, dispname))) + '%s %s:%s %s %s %s\n' % (name.encode('utf-8'), + domainname.encode('utf-8'), + type.encode('utf-8'), prio, + uri.encode('utf-8'), + dispname.encode('utf-8')))) f.write(compressor.flush()) finally: f.close() diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py index 1608c2307..71a5bd0b8 100644 --- a/sphinx/ext/intersphinx.py +++ b/sphinx/ext/intersphinx.py @@ -67,7 +67,7 @@ def read_inventory_v2(f, uri, join, bufsize=16*1024): line = f.readline() projname = line.rstrip()[11:].decode('utf-8') line = f.readline() - version = line.rstrip()[11:] + version = line.rstrip()[11:].decode('utf-8') line = f.readline() if 'zlib' not in line: raise ValueError @@ -84,14 +84,14 @@ def read_inventory_v2(f, uri, join, bufsize=16*1024): buf += chunk lineend = buf.find('\n') while lineend != -1: - yield buf[:lineend] + yield buf[:lineend].decode('utf-8') buf = buf[lineend+1:] lineend = buf.find('\n') assert not buf for line in split_lines(read_chunks()): name, type, prio, location, dispname = line.rstrip().split(None, 4) - if location.endswith('$'): + if location.endswith(u'$'): location = location[:-1] + name location = join(uri, location) invdata.setdefault(type, {})[name] = (projname, version, diff --git a/tests/root/markup.txt b/tests/root/markup.txt index 7b68ba268..f9dfaa896 100644 --- a/tests/root/markup.txt +++ b/tests/root/markup.txt @@ -246,6 +246,8 @@ Invalid index markup... keyword: +.. _ölabel: + Ö... Some strange characters ----------------------------