summaryrefslogtreecommitdiff
path: root/paste/configmiddleware.py
diff options
context:
space:
mode:
authorianb <devnull@localhost>2005-05-04 00:04:41 +0000
committerianb <devnull@localhost>2005-05-04 00:04:41 +0000
commit09e95fe6fa6791a2b85d1c39277127778cfb1be6 (patch)
tree254fe3c0566c4e04c1960d6eccea28c8caff4364 /paste/configmiddleware.py
parent3f4349bcbf3ec9412f6184f0d8cb79f77694418f (diff)
downloadpaste-09e95fe6fa6791a2b85d1c39277127778cfb1be6.tar.gz
Added a globally accessible, threadsafe configuration object (paste.CONFIG)
Diffstat (limited to 'paste/configmiddleware.py')
-rw-r--r--paste/configmiddleware.py26
1 files changed, 24 insertions, 2 deletions
diff --git a/paste/configmiddleware.py b/paste/configmiddleware.py
index 20226f6..bf4768a 100644
--- a/paste/configmiddleware.py
+++ b/paste/configmiddleware.py
@@ -1,7 +1,29 @@
+from paste.util import threadinglocal
+from paste import CONFIG
+from paste import wsgilib
+
def config_middleware(app, config):
def replacement_app(environ, start_response):
- environ['paste.config'] = config.copy()
- return app(environ, start_response)
+ conf = environ['paste.config'] = config.copy()
+ app_iter = None
+ CONFIG.push_thread_config(conf)
+ try:
+ app_iter = app(environ, start_response)
+ finally:
+ if app_iter is None:
+ # An error occurred...
+ CONFIG.pop_thread_config(conf)
+ if type(app_iter) in (list, tuple):
+ # Because it is a concrete iterator (not a generator) we
+ # know the configuration for this thread is no longer
+ # needed:
+ CONFIG.pop_thread_config(conf)
+ return app_iter
+ else:
+ def close_config():
+ CONFIG.pop_thread_config(conf)
+ new_app_iter = wsgilib.add_close(app_iter, close_config)
+ return new_app_iter
return replacement_app