Fix loading JS searchindex data in Py3k.

This commit is contained in:
Georg Brandl
2010-10-29 07:17:14 +02:00
parent 51edd7e810
commit 65505907f1
3 changed files with 11 additions and 2 deletions

View File

@@ -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:

View File

@@ -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("""\

View File

@@ -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