summaryrefslogtreecommitdiff
path: root/paste/makeapp.py
diff options
context:
space:
mode:
authorianb <devnull@localhost>2005-05-16 04:48:52 +0000
committerianb <devnull@localhost>2005-05-16 04:48:52 +0000
commit597e59978a98e2d5aec88e68e8d315d0ef863de6 (patch)
treeb4d297b11932742545a38321f7f40e9a3abbfd38 /paste/makeapp.py
parentc1a903447ca6fe5b3e0138de252ecee42691f355 (diff)
downloadpaste-597e59978a98e2d5aec88e68e8d315d0ef863de6.tar.gz
Renamed error_middleware to errormiddleware; added middleware configuration value; created makeapp with helper functions; refactored server.py to be a bit simpler; consolidated some pyconfig methods
Diffstat (limited to 'paste/makeapp.py')
-rw-r--r--paste/makeapp.py37
1 files changed, 37 insertions, 0 deletions
diff --git a/paste/makeapp.py b/paste/makeapp.py
new file mode 100644
index 0000000..34d1e1c
--- /dev/null
+++ b/paste/makeapp.py
@@ -0,0 +1,37 @@
+"""
+Helper functions for framework build_application functions.
+"""
+
+from paste.util import import_string
+from paste import lint
+from paste import errormiddleware
+from paste import configmiddleware
+
+def apply_conf_middleware(app, conf, first_middleware=()):
+ """
+ Applies any middleware that the configuration specifies,
+ returning the wrapped configuration.
+
+ If first_middleware is given, this middleware is applied most
+ closely to the application (before configuration middleware).
+ """
+ all_middleware = list(first_middleware)
+ all_middleware.extend(conf.get('middleware', []))
+ for middleware in all_middleware:
+ # @@: Should this use plugins too?
+ if isinstance(middleware, (str, unicode)):
+ middleware = import_string.eval_import(middleware)
+ app = middleware(app)
+ if conf.get('lint', False):
+ app = lint.middleware(app)
+ return app
+
+def apply_default_middleware(app, conf):
+ """
+ Applies middleware that is generally always used.
+ """
+ app = errormiddleware.ErrorMiddleware(app)
+ if conf.get('lint', False):
+ app = lint.middleware(app)
+ app = configmiddleware.config_middleware(app, conf)
+ return app