diff options
Diffstat (limited to 'doc/sphinx/_exts/httpdomain/autohttp/common.py')
-rw-r--r-- | doc/sphinx/_exts/httpdomain/autohttp/common.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/doc/sphinx/_exts/httpdomain/autohttp/common.py b/doc/sphinx/_exts/httpdomain/autohttp/common.py new file mode 100644 index 0000000..199e297 --- /dev/null +++ b/doc/sphinx/_exts/httpdomain/autohttp/common.py | |||
@@ -0,0 +1,36 @@ | |||
1 | """ | ||
2 | sphinxcontrib.autohttp.common | ||
3 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
4 | |||
5 | The common functions for web framework reflection. | ||
6 | |||
7 | :copyright: Copyright 2011 by Hong Minhee | ||
8 | :license: BSD, see LICENSE for details. | ||
9 | |||
10 | """ | ||
11 | import six | ||
12 | from six.moves import builtins | ||
13 | from six.moves import reduce | ||
14 | |||
15 | def import_object(import_name): | ||
16 | module_name, expr = import_name.split(':', 1) | ||
17 | mod = __import__(module_name) | ||
18 | mod = reduce(getattr, module_name.split('.')[1:], mod) | ||
19 | globals = builtins | ||
20 | if not isinstance(globals, dict): | ||
21 | globals = globals.__dict__ | ||
22 | return eval(expr, globals, mod.__dict__) | ||
23 | |||
24 | |||
25 | def http_directive(method, path, content): | ||
26 | method = method.lower().strip() | ||
27 | if isinstance(content, six.string_types): | ||
28 | content = content.splitlines() | ||
29 | yield '' | ||
30 | paths = [path] if isinstance(path, six.string_types) else path | ||
31 | for path in paths: | ||
32 | yield '.. http:{method}:: {path}'.format(**locals()) | ||
33 | yield '' | ||
34 | for line in content: | ||
35 | yield ' ' + line | ||
36 | yield '' | ||