changeset 4265:dc253f097867

Split application preparation (middlewares) from running a server
author Florian Krupicka <florian.krupicka@googlemail.com>
date Tue, 05 Aug 2008 22:25:28 +0200
parents fa648504e1cf
children 65af466e6df0
files MoinMoin/web/serving.py
diffstat 1 files changed, 19 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/web/serving.py	Tue Aug 05 18:55:37 2008 +0200
+++ b/MoinMoin/web/serving.py	Tue Aug 05 22:25:28 2008 +0200
@@ -62,17 +62,29 @@
             del environ['REMOTE_ADDR']
         return self.app(environ, start_response)
 
+def make_application(shared=None):
+    from MoinMoin.wsgiapp import application
+
+    if isinstance(shared, dict):
+        application = SharedDataMiddleware(application, shared)
+    elif shared:
+        if shared is True:
+            shared = '/use/share/moin/htdocs'
+
+        if os.path.isdir(shared):
+            mapping = {config.url_prefix_static: shared,
+                       '/favicon.ico': os.path.join(shared, 'favicon.ico'),
+                       '/robots.txt': os.path.join(shared, 'robots.txt')}
+            application = SharedDataMiddleware(application, mapping)
+
+    return application
+
 def run_server(host='localhost', port=8080, docs='/usr/share/moin/htdocs',
                threaded=True, use_debugger=False):
     """ Run a standalone server on specified host/port. """
-    from MoinMoin.wsgiapp import application
-
-    if docs and os.path.isdir(docs):
-        shared = {config.url_prefix_static: docs,
-                  '/favicon.ico': os.path.join(docs, 'favicon.ico'),
-                  '/robots.txt': os.path.join(docs, 'robots.txt')}
-        application = SharedDataMiddleware(application, shared)
+    application = make_application(shared=docs)
 
     run_simple(host, port, application, threaded=threaded,
                use_debugger=use_debugger,
                request_handler=RequestHandler)
+