summaryrefslogtreecommitdiff
path: root/sphinx/util/compat.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-01-02 21:03:56 +0100
committerGeorg Brandl <georg@python.org>2010-01-02 21:03:56 +0100
commitfaeec5cbbbcaec4a0c2ce12f0d41ecf3f225f5b4 (patch)
tree50fe275b8db2751541d4d20be7656aca3bc0eed4 /sphinx/util/compat.py
parented78dc7ff0102a2d10d934259f5c046fc5e280f6 (diff)
parentf3a2854ba97b33548c92490e0731e91014fa7c20 (diff)
downloadsphinx-git-faeec5cbbbcaec4a0c2ce12f0d41ecf3f225f5b4.tar.gz
merge with trunk
Diffstat (limited to 'sphinx/util/compat.py')
-rw-r--r--sphinx/util/compat.py69
1 files changed, 9 insertions, 60 deletions
diff --git a/sphinx/util/compat.py b/sphinx/util/compat.py
index 885a458e3..3fbfe4b26 100644
--- a/sphinx/util/compat.py
+++ b/sphinx/util/compat.py
@@ -11,7 +11,7 @@
from docutils import nodes
-# function missing in 0.5 SVN
+# function missing in docutils 0.5
def make_admonition(node_class, name, arguments, options, content, lineno,
content_offset, block_text, state, state_machine):
#if not content:
@@ -35,64 +35,13 @@ def make_admonition(node_class, name, arguments, options, content, lineno,
return [admonition_node]
-# support the class-style Directive interface even when using docutils 0.4
+# backwards-compatibility aliases for helpers in older Sphinx versions that
+# supported the docutils 0.4 directive function interface
-try:
- from docutils.parsers.rst import Directive
+from docutils.parsers.rst import Directive
-except ImportError:
- class Directive(object):
- """
- Fake Directive class to allow Sphinx directives to be written in
- class style.
- """
- required_arguments = 0
- optional_arguments = 0
- final_argument_whitespace = False
- option_spec = None
- has_content = False
-
- def __init__(self, name, arguments, options, content, lineno,
- content_offset, block_text, state, state_machine):
- self.name = name
- self.arguments = arguments
- self.options = options
- self.content = content
- self.lineno = lineno
- self.content_offset = content_offset
- self.block_text = block_text
- self.state = state
- self.state_machine = state_machine
-
- def run(self):
- raise NotImplementedError('Must override run() is subclass.')
-
- def directive_dwim(obj):
- """
- Return something usable with register_directive(), regardless if
- class or function. For that, we need to convert classes to a
- function for docutils 0.4.
- """
- if isinstance(obj, type) and issubclass(obj, Directive):
- def _class_directive(name, arguments, options, content,
- lineno, content_offset, block_text,
- state, state_machine):
- return obj(name, arguments, options, content,
- lineno, content_offset, block_text,
- state, state_machine).run()
- _class_directive.options = obj.option_spec
- _class_directive.content = obj.has_content
- _class_directive.arguments = (obj.required_arguments,
- obj.optional_arguments,
- obj.final_argument_whitespace)
- return _class_directive
- return obj
-
-else:
- def directive_dwim(obj):
- """
- Return something usable with register_directive(), regardless if
- class or function. Nothing to do here, because docutils 0.5 takes
- care of converting functions itself.
- """
- return obj
+def directive_dwim(obj):
+ import warnings
+ warnings.warn('directive_dwim is deprecated and no longer needed',
+ DeprecationWarning, stacklevel=2)
+ return obj