diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-06-02 18:40:52 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-06-02 18:40:52 +0000 |
| commit | f0fd9d62c991afe0b125beb6d7f583be9500de84 (patch) | |
| tree | ba0ac4df571b3a3448b73edc0b5ed7651d161577 /repoze/bfg/settings.py | |
| parent | db0467ca526c07ab719de7e74c84882d3297ce83 (diff) | |
| download | pyramid-f0fd9d62c991afe0b125beb6d7f583be9500de84.tar.gz pyramid-f0fd9d62c991afe0b125beb6d7f583be9500de84.tar.bz2 pyramid-f0fd9d62c991afe0b125beb6d7f583be9500de84.zip | |
- Add API named ``repoze.bfg.settings.get_settings`` which retrieves a
derivation of values passed as the ``options`` value of
``repoze.bfg.router.make_app``. This API should be preferred
instead of using getUtility(ISettings). I added a new
``repoze.bfg.settings`` API document as well.
Diffstat (limited to 'repoze/bfg/settings.py')
| -rw-r--r-- | repoze/bfg/settings.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/repoze/bfg/settings.py b/repoze/bfg/settings.py index 795b5932a..df2a5e99e 100644 --- a/repoze/bfg/settings.py +++ b/repoze/bfg/settings.py @@ -1,14 +1,30 @@ import os +from zope.component import queryUtility from zope.interface import implements from repoze.bfg.interfaces import ISettings -class Settings(object): +class Settings(dict): implements(ISettings) - def __init__(self, options): - options = get_options(options) - self.__dict__.update(options) + def __getattr__(self, name): + # backwards compatibility + try: + return self[name] + except KeyError: + raise AttributeError(name) + +def get_settings(): + """ + Return a 'settings' object for the current application. A + 'settings' object is a dictionary-like object that contains + key/value pairs based on the dictionary passed as the ``options`` + argument to the ``repoze.bfg.router.make_app`` API. + + For backwards compatibility, dictionary keys can also be looked up + as attributes of the settings object. + """ + return queryUtility(ISettings) def asbool(s): s = str(s).strip() |
