mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-07-31 08:38:07 -05:00
Rename util.json to util.jsdump because it doesn't generate valid JSON anymore.
The JSON html builder still needs simplejson to work.
This commit is contained in:
+19
-4
@@ -26,7 +26,7 @@ from docutils.frontend import OptionParser
|
||||
from docutils.readers.doctree import Reader as DoctreeReader
|
||||
|
||||
from sphinx import addnodes, locale, __version__
|
||||
from sphinx.util import ensuredir, relative_uri, SEP, os_path, json, texescape
|
||||
from sphinx.util import ensuredir, relative_uri, SEP, os_path, texescape
|
||||
from sphinx.htmlhelp import build_hhx
|
||||
from sphinx.htmlwriter import HTMLWriter, HTMLTranslator, SmartyPantsHTMLTranslator
|
||||
from sphinx.textwriter import TextWriter
|
||||
@@ -36,6 +36,14 @@ from sphinx.highlighting import PygmentsBridge
|
||||
from sphinx.util.console import bold, purple, darkgreen
|
||||
from sphinx.search import js_index
|
||||
|
||||
try:
|
||||
import json
|
||||
except ImportError:
|
||||
try:
|
||||
import ssimplejson as json
|
||||
except ImportError:
|
||||
json = None
|
||||
|
||||
# side effect: registers roles and directives
|
||||
from sphinx import roles
|
||||
from sphinx import directives
|
||||
@@ -802,9 +810,6 @@ class SerializingHTMLBuilder(StandaloneHTMLBuilder):
|
||||
self.init_translator_class()
|
||||
self.templates = None # no template bridge necessary
|
||||
|
||||
indexer_format = property(lambda x: x.implementation, doc='''
|
||||
Alias the indexer format to the serilization implementation''')
|
||||
|
||||
def get_target_uri(self, docname, typ=None):
|
||||
if docname == 'index':
|
||||
return ''
|
||||
@@ -866,6 +871,7 @@ class PickleHTMLBuilder(SerializingHTMLBuilder):
|
||||
A Builder that dumps the generated HTML into pickle files.
|
||||
"""
|
||||
implementation = pickle
|
||||
indexer_format = pickle
|
||||
name = 'pickle'
|
||||
out_suffix = '.fpickle'
|
||||
globalcontext_filename = 'globalcontext.pickle'
|
||||
@@ -877,11 +883,20 @@ class JSONHTMLBuilder(SerializingHTMLBuilder):
|
||||
A builder that dumps the generated HTML into JSON files.
|
||||
"""
|
||||
implementation = json
|
||||
indexer_format = json
|
||||
name = 'json'
|
||||
out_suffix = '.fjson'
|
||||
globalcontext_filename = 'globalcontext.json'
|
||||
searchindex_filename = 'searchindex.json'
|
||||
|
||||
def init(self):
|
||||
if json is None:
|
||||
from sphinx.application import SphinxError
|
||||
raise SphinxError('The module simplejson (or json in Python >= 2.6) '
|
||||
'is not available. The JSONHTMLBuilder builder '
|
||||
'will not work.')
|
||||
SerializingHTMLBuilder.init(self)
|
||||
|
||||
|
||||
class HTMLHelpBuilder(StandaloneHTMLBuilder):
|
||||
"""
|
||||
|
||||
+4
-6
@@ -15,7 +15,7 @@ from cStringIO import StringIO
|
||||
from docutils.nodes import Text, NodeVisitor
|
||||
|
||||
from sphinx.util.stemmer import PorterStemmer
|
||||
from sphinx.util import json, rpartition
|
||||
from sphinx.util import jsdump, rpartition
|
||||
|
||||
|
||||
word_re = re.compile(r'\w+(?u)')
|
||||
@@ -37,22 +37,20 @@ class _JavaScriptIndex(object):
|
||||
"""
|
||||
The search index as javascript file that calls a function
|
||||
on the documentation search object to register the index.
|
||||
This serializing system does not support chaining because
|
||||
simplejson (which it depends on) doesn't support it either.
|
||||
"""
|
||||
|
||||
PREFIX = 'Search.setIndex('
|
||||
SUFFIX = ')'
|
||||
|
||||
def dumps(self, data):
|
||||
return self.PREFIX + json.dumps(data) + self.SUFFIX
|
||||
return self.PREFIX + jsdump.dumps(data) + self.SUFFIX
|
||||
|
||||
def loads(self, s):
|
||||
data = s[len(self.PREFIX):-len(self.SUFFIX)]
|
||||
if not data or not s.startswith(self.PREFIX) or not \
|
||||
s.endswith(self.SUFFIX):
|
||||
raise ValueError('invalid data')
|
||||
return json.loads(data)
|
||||
return jsdump.loads(data)
|
||||
|
||||
def dump(self, data, f):
|
||||
f.write(self.dumps(data))
|
||||
@@ -95,7 +93,7 @@ class IndexBuilder(object):
|
||||
passed to the `feed` method.
|
||||
"""
|
||||
formats = {
|
||||
'json': json,
|
||||
'jsdump': jsdump,
|
||||
'pickle': pickle
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user