From f0fd9d62c991afe0b125beb6d7f583be9500de84 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Tue, 2 Jun 2009 18:40:52 +0000 Subject: - 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. --- repoze/bfg/settings.py | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) (limited to 'repoze/bfg/settings.py') 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() -- cgit v1.2.3