blob: 199e2972c0aa97420613e66225ec0e8b9d520362 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
"""
sphinxcontrib.autohttp.common
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The common functions for web framework reflection.
:copyright: Copyright 2011 by Hong Minhee
:license: BSD, see LICENSE for details.
"""
import six
from six.moves import builtins
from six.moves import reduce
def import_object(import_name):
module_name, expr = import_name.split(':', 1)
mod = __import__(module_name)
mod = reduce(getattr, module_name.split('.')[1:], mod)
globals = builtins
if not isinstance(globals, dict):
globals = globals.__dict__
return eval(expr, globals, mod.__dict__)
def http_directive(method, path, content):
method = method.lower().strip()
if isinstance(content, six.string_types):
content = content.splitlines()
yield ''
paths = [path] if isinstance(path, six.string_types) else path
for path in paths:
yield '.. http:{method}:: {path}'.format(**locals())
yield ''
for line in content:
yield ' ' + line
yield ''
|