summaryrefslogtreecommitdiff
path: root/repoze/bfg/settings.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2010-10-25 10:29:31 -0400
committerChris McDonough <chrism@plope.com>2010-10-25 10:29:31 -0400
commit64372401084889a440c9d990a0febc221e3e4b5c (patch)
treec8939a341505d19f19fa6918d264b4e1d95326f8 /repoze/bfg/settings.py
parentc8e78c2037806f3e5dab57de635bf80865b7061d (diff)
downloadpyramid-64372401084889a440c9d990a0febc221e3e4b5c.tar.gz
pyramid-64372401084889a440c9d990a0febc221e3e4b5c.tar.bz2
pyramid-64372401084889a440c9d990a0febc221e3e4b5c.zip
first pass at converting bfg to pyramid namespace
Diffstat (limited to 'repoze/bfg/settings.py')
-rw-r--r--repoze/bfg/settings.py85
1 files changed, 0 insertions, 85 deletions
diff --git a/repoze/bfg/settings.py b/repoze/bfg/settings.py
deleted file mode 100644
index 5e1181809..000000000
--- a/repoze/bfg/settings.py
+++ /dev/null
@@ -1,85 +0,0 @@
-import os
-
-from zope.interface import implements
-
-from repoze.bfg.interfaces import ISettings
-
-from repoze.bfg.threadlocal import get_current_registry
-
-class Settings(dict):
- """ Deployment settings. Update application settings (usually
- from PasteDeploy keywords) with framework-specific key/value pairs
- (e.g. find ``BFG_DEBUG_AUTHORIZATION`` in os.environ and jam into
- keyword args)."""
- implements(ISettings)
- # _environ_ is dep inj for testing
- def __init__(self, d=None, _environ_=os.environ, **kw):
- if d is None:
- d = {}
- dict.__init__(self, d, **kw)
- eget = _environ_.get
- config_debug_all = self.get('debug_all', '')
- eff_debug_all = asbool(eget('BFG_DEBUG_ALL', config_debug_all))
- config_reload_all = self.get('reload_all', '')
- eff_reload_all = asbool(eget('BFG_RELOAD_ALL',config_reload_all))
- config_debug_auth = self.get('debug_authorization', '')
- eff_debug_auth = asbool(eget('BFG_DEBUG_AUTHORIZATION',
- config_debug_auth))
- config_debug_notfound = self.get('debug_notfound', '')
- eff_debug_notfound = asbool(eget('BFG_DEBUG_NOTFOUND',
- config_debug_notfound))
- config_debug_templates = self.get('debug_templates', '')
- eff_debug_templates = asbool(eget('BFG_DEBUG_TEMPLATES',
- config_debug_templates))
- config_reload_templates = self.get('reload_templates', '')
- eff_reload_templates = asbool(eget('BFG_RELOAD_TEMPLATES',
- config_reload_templates))
- config_reload_resources = self.get('reload_resources', '')
- eff_reload_resources = asbool(eget('BFG_RELOAD_RESOURCES',
- config_reload_resources))
- configure_zcml = self.get('configure_zcml', '')
- eff_configure_zcml = eget('BFG_CONFIGURE_ZCML', configure_zcml)
- locale_name = self.get('default_locale_name', 'en')
- eff_locale_name = eget('BFG_DEFAULT_LOCALE_NAME', locale_name)
-
- update = {
- 'debug_authorization': eff_debug_all or eff_debug_auth,
- 'debug_notfound': eff_debug_all or eff_debug_notfound,
- 'debug_templates': eff_debug_all or eff_debug_templates,
- 'reload_templates': eff_reload_all or eff_reload_templates,
- 'reload_resources':eff_reload_all or eff_reload_resources,
- 'configure_zcml':eff_configure_zcml,
- 'default_locale_name':eff_locale_name,
- }
-
- self.update(update)
-
- 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 ``settings``
- argument to the :class:`repoze.bfg.configuration.Configurator`
- constructor or the :func:`repoze.bfg.router.make_app` API.
-
- .. note:: For backwards compatibility, dictionary keys can also be
- looked up as attributes of the settings object.
-
- .. note:: the
- :class:`repoze.bfg.configuration.Configurator.get_settings` method
- performs the same duty.
- """
- reg = get_current_registry()
- return reg.queryUtility(ISettings)
-
-def asbool(s):
- s = str(s).strip()
- return s.lower() in ('t', 'true', 'y', 'yes', 'on', '1')
-