From 65505907f1f09ccc2385d21758254f9516abb5de Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Fri, 29 Oct 2010 07:17:14 +0200 Subject: [PATCH] Fix loading JS searchindex data in Py3k. --- sphinx/builders/html.py | 6 +++++- sphinx/util/jsdump.py | 4 +++- sphinx/util/pycompat.py | 3 +++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/sphinx/builders/html.py b/sphinx/builders/html.py index cdeb334a2..b85e94423 100644 --- a/sphinx/builders/html.py +++ b/sphinx/builders/html.py @@ -614,7 +614,11 @@ class StandaloneHTMLBuilder(Builder): def load_indexer(self, docnames): keep = set(self.env.all_docs) - set(docnames) try: - f = open(path.join(self.outdir, self.searchindex_filename), 'rb') + searchindexfn = path.join(self.outdir, self.searchindex_filename) + if self.indexer_dumps_unicode: + f = codecs.open(searchindexfn, 'r', encoding='utf-8') + else: + f = open(searchindexfn, 'rb') try: self.indexer.load(f, self.indexer_format) finally: diff --git a/sphinx/util/jsdump.py b/sphinx/util/jsdump.py index e357128c2..bfa1895f4 100644 --- a/sphinx/util/jsdump.py +++ b/sphinx/util/jsdump.py @@ -12,6 +12,8 @@ import re +from sphinx.util.pycompat import u + _str_re = re.compile(r'"(\\\\|\\"|[^"])*"') _int_re = re.compile(r'\d+') _name_re = re.compile(r'[a-zA-Z]\w*') @@ -50,7 +52,7 @@ def encode_string(s): return '"' + str(ESCAPE_ASCII.sub(replace, s)) + '"' def decode_string(s): - return ESCAPED.sub(lambda m: eval('u"'+m.group()+'"'), s) + return ESCAPED.sub(lambda m: eval(u + '"' + m.group() + '"'), s) reswords = set("""\ diff --git a/sphinx/util/pycompat.py b/sphinx/util/pycompat.py index 319312a75..5834b7b72 100644 --- a/sphinx/util/pycompat.py +++ b/sphinx/util/pycompat.py @@ -23,6 +23,8 @@ if sys.version_info >= (3, 0): def b(s): return s.encode('utf-8') bytes = bytes + # prefix for Unicode strings + u = '' # support for running 2to3 over config files def convert_with_2to3(filepath): from lib2to3.refactor import RefactoringTool, get_fixers_from_package @@ -45,6 +47,7 @@ else: class_types = (type, ClassType) b = str bytes = str + u = 'u' # no need to refactor on 2.x versions convert_with_2to3 = None