Commits

Hong Minhee  committed 8e964f4

Move common parts from __init__.py to common submodule

  • Participants
  • Parent commits 05274cb

Comments (0)

Files changed (4)

File httpdomain/sphinxcontrib/autohttp/__init__.py

     :license: BSD, see LICENSE for details.
 
 """
-
-
-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, basestring):
-        content = content.splitlines()
-    yield ''
-    yield '.. http:{method}:: {path}'.format(**locals())
-    yield ''
-    for line in content:
-        yield '   ' + line
-    yield ''

File httpdomain/sphinxcontrib/autohttp/bottle.py

 from sphinx.pycode import ModuleAnalyzer
 
 from sphinxcontrib import httpdomain
-from sphinxcontrib import autohttp
+from sphinxcontrib.autohttp.common import http_directive, import_object
 
 
 def translate_bottle_rule(app, rule):
         return frozenset(endpoints)
 
     def make_rst(self):
-        app = autohttp.import_object(self.arguments[0])
+        app = import_object(self.arguments[0])
         for method, path, target in get_routes(app):
             endpoint = target.name or target.callback.__name__
             if self.endpoints and endpoint not in self.endpoints:
             if not docstring and 'include-empty-docstring' not in self.options:
                 continue
             docstring = prepare_docstring(docstring)
-            for line in autohttp.http_directive(method, path, docstring):
+            for line in http_directive(method, path, docstring):
                 yield line
 
     def run(self):

File httpdomain/sphinxcontrib/autohttp/common.py

+"""
+    sphinxcontrib.autohttp.common
+    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+    The common functions for web framework reflection.
+
+    :copyright: Copyright 2011 by Hong Minhee
+    :license: BSD, see LICENSE for details.
+
+"""
+
+import __builtin__
+
+
+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 = __builtin__
+    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, basestring):
+        content = content.splitlines()
+    yield ''
+    yield '.. http:{method}:: {path}'.format(**locals())
+    yield ''
+    for line in content:
+        yield '   ' + line
+    yield ''

File httpdomain/sphinxcontrib/autohttp/flask.py

 from sphinx.pycode import ModuleAnalyzer
 
 from sphinxcontrib import httpdomain
-from sphinxcontrib import autohttp
+from sphinxcontrib.autohttp.common import http_directive, import_object
 
 
 def translate_werkzeug_rule(rule):
         return frozenset(blueprints)
 
     def make_rst(self):
-        app = autohttp.import_object(self.arguments[0])
+        app = import_object(self.arguments[0])
         for method, path, endpoint in get_routes(app):
             try:
                 blueprint, endpoint_internal = endpoint.split('.')
             if not docstring and 'include-empty-docstring' not in self.options:
                 continue
             docstring = prepare_docstring(docstring)
-            for line in autohttp.http_directive(method, path, docstring):
+            for line in http_directive(method, path, docstring):
                 yield line
 
     def run(self):