diff options
author | pjenvey <devnull@localhost> | 2007-07-06 21:15:29 +0000 |
---|---|---|
committer | pjenvey <devnull@localhost> | 2007-07-06 21:15:29 +0000 |
commit | d8c7f277fe4d0ebb05ffc82f9052e4c5038e68a5 (patch) | |
tree | 5b9139ed670a284142863ef552e3b59abb3c6523 /paste/config.py | |
parent | 2739d6d420bc3488776906fb8b7b207feae3c3ac (diff) | |
download | paste-d8c7f277fe4d0ebb05ffc82f9052e4c5038e68a5.tar.gz |
o allow DispatchingConfigs to customize their SOP name attribute
o inline current_conf, add current as an alias
o allow customizing ConfigMiddleware's environ key
Diffstat (limited to 'paste/config.py')
-rw-r--r-- | paste/config.py | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/paste/config.py b/paste/config.py index f6ef16f..c531579 100644 --- a/paste/config.py +++ b/paste/config.py @@ -19,8 +19,8 @@ class DispatchingConfig(StackedObjectProxy): # configuration to itself? Probably the conf should become # resolved, and get rid of this delegation wrapper - def __init__(self): - super(DispatchingConfig, self).__init__(name='DispatchingConfig') + def __init__(self, name='DispatchingConfig'): + super(DispatchingConfig, self).__init__(name=name) self.__dict__['_process_configs'] = [] def push_thread_config(self, conf): @@ -75,40 +75,41 @@ class DispatchingConfig(StackedObjectProxy): raise AttributeError( "No configuration has been registered for this process " "or thread") - - def current_conf(self): - return self._current_obj() + current = current_conf = _current_obj CONFIG = DispatchingConfig() +no_config = object() class ConfigMiddleware(RegistryManager): """ - A WSGI middleware that adds a ``paste.config`` key to the request - environment, as well as registering the configuration temporarily - (for the length of the request) with ``paste.config.CONFIG`` (or - any other ``DispatchingConfig`` object). + A WSGI middleware that adds a ``paste.config`` key (by default) + to the request environment, as well as registering the + configuration temporarily (for the length of the request) with + ``paste.config.CONFIG`` (or any other ``DispatchingConfig`` + object). """ - def __init__(self, application, config, dispatching_config=CONFIG): + def __init__(self, application, config, dispatching_config=CONFIG, + environ_key='paste.config'): """ This delegates all requests to `application`, adding a *copy* of the configuration `config`. """ def register_config(environ, start_response): - popped_config = None - if 'paste.config' in environ: - popped_config = environ['paste.config'] - - conf = environ['paste.config'] = config.copy() - environ['paste.registry'].register(dispatching_config, conf) + popped_config = environ.get(environ_key, no_config) + current_config = environ[environ_key] = config.copy() + environ['paste.registry'].register(dispatching_config, + current_config) try: app_iter = application(environ, start_response) finally: - if popped_config is not None: - environ['paste.config'] = popped_config + if popped_config is no_config: + environ.pop(environ_key, None) + else: + environ[environ_key] = popped_config return app_iter - + super(self.__class__, self).__init__(register_config) def make_config_filter(app, global_conf, **local_conf): |