Commits

Georg Brandl committed 49747f5

Fix loading JS searchindex data in Py3k.

  • Participants
  • Parent commits 24259fb

Comments (0)

Files changed (3)

sphinx/builders/html.py

     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:

sphinx/util/jsdump.py

 
 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*')
     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("""\

sphinx/util/pycompat.py

     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
     class_types = (type, ClassType)
     b = str
     bytes = str
+    u = 'u'
     # no need to refactor on 2.x versions
     convert_with_2to3 = None