summaryrefslogtreecommitdiff
path: root/sphinx
diff options
context:
space:
mode:
authorgeorg.brandl <devnull@localhost>2008-09-24 12:01:16 +0000
committergeorg.brandl <devnull@localhost>2008-09-24 12:01:16 +0000
commitbc9523d405514d3a86f4b0dba0e0389d4e7a8197 (patch)
tree512846d8745bac5e85aab829da0f9f03cdd1894f /sphinx
parent8eaeb1c4f2af3fabc6d6c4adf8c590e57905be41 (diff)
downloadsphinx-bc9523d405514d3a86f4b0dba0e0389d4e7a8197.tar.gz
Rename util.json to util.jsdump because it doesn't generate valid JSON anymore.
The JSON html builder still needs simplejson to work.
Diffstat (limited to 'sphinx')
-rw-r--r--sphinx/builder.py23
-rw-r--r--sphinx/search.py10
-rw-r--r--sphinx/util/jsdump.py (renamed from sphinx/util/json.py)0
3 files changed, 23 insertions, 10 deletions
diff --git a/sphinx/builder.py b/sphinx/builder.py
index 2a1379bc..22895954 100644
--- a/sphinx/builder.py
+++ b/sphinx/builder.py
@@ -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):
"""
diff --git a/sphinx/search.py b/sphinx/search.py
index 8241c45c..46ff986d 100644
--- a/sphinx/search.py
+++ b/sphinx/search.py
@@ -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
}
diff --git a/sphinx/util/json.py b/sphinx/util/jsdump.py
index a2fda2b8..a2fda2b8 100644
--- a/sphinx/util/json.py
+++ b/sphinx/util/jsdump.py