2 sphinxcontrib.autohttp.tornado
3 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 The sphinx.ext.autodoc-style HTTP API reference builder (from Tornado)
6 for sphinxcontrib.httpdomain.
8 :copyright: Copyright 2013 by Rodrigo Machado
9 :license: BSD, see LICENSE
for details.
17from docutils import nodes
18from docutils.parsers.rst import directives
19from docutils.statemachine import ViewList
21from sphinx.util import force_decode
22from sphinx.util.compat import Directive
23from sphinx.util.nodes import nested_parse_with_titles
24from sphinx.util.docstrings import prepare_docstring
25from sphinx.pycode import ModuleAnalyzer
27from sphinxcontrib import httpdomain
28from sphinxcontrib.autohttp.common import http_directive, import_object
31def translate_tornado_rule(app, rule):
33 for name, filter, conf
in app.router.parse_rule(rule):
37 if filter != app.router.default_filter
or conf:
50 for spec
in app.handlers[0][1]:
51 handler = spec.handler_class
52 doc_methods =
list(handler.SUPPORTED_METHODS)
53 if 'HEAD' in doc_methods:
54 doc_methods.remove(
'HEAD')
55 if 'OPTIONS' in doc_methods:
56 doc_methods.remove(
'OPTIONS')
58 for method
in doc_methods:
59 maybe_method = getattr(handler, method.lower(),
None)
60 if (inspect.isfunction(maybe_method)
or
61 inspect.ismethod(maybe_method)):
62 yield method.lower(), spec.regex.pattern, handler
66 if path.endswith(
'$'):
71class AutoTornadoDirective(Directive):
74 required_arguments = 1
75 option_spec = {
'endpoints': directives.unchanged,
76 'undoc-endpoints': directives.unchanged,
77 'include-empty-docstring': directives.unchanged}
81 endpoints = self.options.
get(
'endpoints',
None)
84 return frozenset(re.split(
r'\s*,\s*', endpoints))
88 undoc_endpoints = self.options.
get(
'undoc-endpoints',
None)
89 if not undoc_endpoints:
91 return frozenset(re.split(
r'\s*,\s*', undoc_endpoints))
96 class_name = handler.__name__
97 method_name = getattr(handler, method).__name__
98 endpoint =
'.'.join((class_name, method_name))
105 docstring = getattr(handler, method).__doc__
or ''
109 if not docstring
and 'include-empty-docstring' not in self.options:
111 docstring = prepare_docstring(docstring)
116 node = nodes.section()
117 node.document = self.state.document
120 result.append(line,
'<autotornado>')
121 nested_parse_with_titles(self.state, result, node)
126 if 'http' not in app.domains:
127 httpdomain.setup(app)
128 app.add_directive(
'autotornado', AutoTornadoDirective)
def undoc_endpoints(self)
static int list
Set if we should print a list of currently running services.
static int get
Get DID Documement for DID Flag.
def http_directive(method, path, content)
def import_object(import_name)