diff options
author | Ryan Petrello <lists@ryanpetrello.com> | 2012-03-06 23:44:29 -0500 |
---|---|---|
committer | Ryan Petrello <lists@ryanpetrello.com> | 2012-03-06 23:44:29 -0500 |
commit | 4931a0cce6a6f3860438c9de291cab8991b25055 (patch) | |
tree | 241113b7d8f6306db82f5e7789371052d2ec6566 /pecan/configuration.py | |
parent | 054e1c4828f3d719da92a679fc576e7469e4a539 (diff) | |
download | pecan-4931a0cce6a6f3860438c9de291cab8991b25055.tar.gz |
Improving `pecan.configuration.set_config` to take a dict *or* file.
Diffstat (limited to 'pecan/configuration.py')
-rw-r--r-- | pecan/configuration.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/pecan/configuration.py b/pecan/configuration.py index 5756519..b2d08f6 100644 --- a/pecan/configuration.py +++ b/pecan/configuration.py @@ -179,15 +179,23 @@ def initconf(): return conf_from_dict(DEFAULT) -def set_config(name, overwrite=False): +def set_config(config, overwrite=False): ''' Updates the global configuration a filename. - :param name: filename, as a string. + :param config: Can be a dictionary containing configuration, or a string which + represents a (relative) configuration filename. ''' - conf = conf_from_file(name) - _runtime_conf.update(conf) + if overwrite is True: + _runtime_conf.__values__ == {} + + if isinstance(config, basestring): + _runtime_conf.update(conf_from_file(config)) + elif isinstance(config, dict): + _runtime_conf.update(conf_from_dict(config)) + else: + raise TypeError('%s is neither a dictionary of a string.' % config) _runtime_conf = initconf() |