2 sphinxcontrib.autohttp.bottle
3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 The sphinx.ext.autodoc-style HTTP API reference builder (from Bottle)
6 for sphinxcontrib.httpdomain.
8 :copyright: Copyright 2012 by Jameel Al-Aziz
9 :license: BSD, see LICENSE
for details.
16from docutils import nodes
17from docutils.parsers.rst import directives
18from docutils.statemachine import ViewList
20from sphinx.util import force_decode
21from sphinx.util.compat import Directive
22from sphinx.util.nodes import nested_parse_with_titles
23from sphinx.util.docstrings import prepare_docstring
24from sphinx.pycode import ModuleAnalyzer
26from sphinxcontrib import httpdomain
27from sphinxcontrib.autohttp.common import http_directive, import_object
30def translate_bottle_rule(app, rule):
32 if hasattr(app.router,
"parse_rule"):
33 iterator = app.router.parse_rule(rule)
35 iterator = app.router._itertokens(rule)
36 for name, filter, conf
in iterator:
40 if (filter != app.router.default_filter
and filter !=
'default')\
54 for route
in app.routes:
56 yield route.method, path, route
59class AutobottleDirective(Directive):
62 required_arguments = 1
63 option_spec = {
'endpoints': directives.unchanged,
64 'undoc-endpoints': directives.unchanged,
65 'include-empty-docstring': directives.unchanged}
69 endpoints = self.options.
get(
'endpoints',
None)
72 return frozenset(re.split(
r'\s*,\s*', endpoints))
76 undoc_endpoints = self.options.
get(
'undoc-endpoints',
None)
77 if not undoc_endpoints:
79 return frozenset(re.split(
r'\s*,\s*', undoc_endpoints))
84 endpoint = target.name
or target.callback.__name__
89 view = target.callback
90 docstring = view.__doc__
or ''
91 if not isinstance(docstring, six.text_type):
92 analyzer = ModuleAnalyzer.for_module(view.__module__)
93 docstring = force_decode(docstring, analyzer.encoding)
94 if not docstring
and 'include-empty-docstring' not in self.options:
96 docstring = prepare_docstring(docstring)
101 node = nodes.section()
102 node.document = self.state.document
105 result.append(line,
'<autobottle>')
106 nested_parse_with_titles(self.state, result, node)
111 if 'http' not in app.domains:
112 httpdomain.setup(app)
113 app.add_directive(
'autobottle', AutobottleDirective)
def undoc_endpoints(self)
static int get
Get DID Documement for DID Flag.
def translate_bottle_rule(app, rule)
def http_directive(method, path, content)
def import_object(import_name)