common.py (1020B)
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 ''