summaryrefslogtreecommitdiff
path: root/repoze/bfg/settings.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-01-11 02:20:52 +0000
committerChris McDonough <chrism@agendaless.com>2009-01-11 02:20:52 +0000
commit358dc276d28fb395a9a742ff53dc66ee115c58ad (patch)
treec92dd9bdd24f4b473a7e56a7a498aac046dd4ed4 /repoze/bfg/settings.py
parentbe268487581bf94086ecc18904113d71237612e1 (diff)
downloadpyramid-358dc276d28fb395a9a742ff53dc66ee115c58ad.tar.gz
pyramid-358dc276d28fb395a9a742ff53dc66ee115c58ad.tar.bz2
pyramid-358dc276d28fb395a9a742ff53dc66ee115c58ad.zip
Merge router-simplify branch. Changelog below.
Bug Fixes --------- - Fix a bug where the Paste configuration's ``unicode_path_segments`` (and os.environ's ``BFG_UNICODE_PATH_SEGMENTS``) may have been defaulting to false in some circumstances. It now always defaults to true, matching the documentation and intent. - The ``repoze.bfg.traversal.find_model`` API did not work properly when passed a ``path`` argument which was unicode and contained high-order bytes when the ``unicode_path_segments`` or ``BFG_UNICODE_PATH_SEGMENTS`` configuration variables were "true". - A new module was added: ``repoze.bfg.settings``. This contains deployment-settings-related code. Behavior Changes ---------------- - The ``make_app`` callable within ``repoze.bfg.router`` now registers the ``root_policy`` argument as a utility (unnamed, using the new ``repoze.bfg.interfaces.IRootFactory`` as a provides interface) rather than passing it as the first argument to the ``repoze.bfg.router.Router`` class. As a result the ``repoze.bfg.router.Router`` router class only accepts a single argument: ``registry``. The ``repoze.bfg.router.Router`` class retrieves the root policy via a utility lookup now. The ``repoze.bfg.router.make_app`` API also now performs some important application registrations that were previously handled inside ``repoze.bfg.registry.makeRegistry``. - The ``repoze.bfg.settings.Settings`` class (an instance of which is registered as a utility providing ``repoze.bfg.interfaces.ISettings`` when any application is started) now automatically calls ``repoze.bfg.settings.get_options`` on the options passed to its constructor. This means that usage of ``get_options`` within an application's ``make_app`` function is no longer required (the "raw" ``options`` dict or None may be passed). Deprecations ------------ - Moved the ``repoze.bfg.registry.Settings`` class. This has been moved to ``repoze.bfg.settings.Settings``. A deprecation warning is issued when it is imported from the older location. - Moved the ``repoze.bfg.registry.get_options`` function This has been moved to ``repoze.bfg.settings.get_options``. A deprecation warning is issued when it is imported from the older location. - The ``repoze.bfg.interfaces.IRootPolicy`` interface was renamed within the interfaces package. It has been renamed to ``IRootFactory``. A deprecation warning is issued when it is imported from the older location.
Diffstat (limited to 'repoze/bfg/settings.py')
-rw-r--r--repoze/bfg/settings.py55
1 files changed, 55 insertions, 0 deletions
diff --git a/repoze/bfg/settings.py b/repoze/bfg/settings.py
new file mode 100644
index 000000000..7cd19fcf7
--- /dev/null
+++ b/repoze/bfg/settings.py
@@ -0,0 +1,55 @@
+import os
+
+from zope.interface import implements
+
+from repoze.bfg.interfaces import ISettings
+
+class Settings(object):
+ implements(ISettings)
+
+ # defaults
+ reload_templates = False
+ debug_notfound = False
+ debug_authorization = False
+ unicode_path_segments = True
+
+ def __init__(self, options):
+ options = get_options(options)
+ self.__dict__.update(options)
+
+def asbool(s):
+ s = str(s).strip()
+ return s.lower() in ('t', 'true', 'y', 'yes', 'on', '1')
+
+def get_options(kw, environ=os.environ):
+ """ Update PasteDeploy application settings keywords with
+ framework-specific key/value pairs (e.g. find
+ 'BFG_DEBUG_AUTHORIZATION' in os.environ and jam into keyword
+ args)."""
+ # environ is passed in for unit tests
+ eget = environ.get
+ config_debug_all = kw.get('debug_all', '')
+ effective_debug_all = asbool(eget('BFG_DEBUG_ALL',
+ config_debug_all))
+ config_debug_auth = kw.get('debug_authorization', '')
+ effective_debug_auth = asbool(eget('BFG_DEBUG_AUTHORIZATION',
+ config_debug_auth))
+ config_debug_notfound = kw.get('debug_notfound', '')
+ effective_debug_notfound = asbool(eget('BFG_DEBUG_NOTFOUND',
+ config_debug_notfound))
+ config_reload_templates = kw.get('reload_templates', '')
+ effective_reload_templates = asbool(eget('BFG_RELOAD_TEMPLATES',
+ config_reload_templates))
+ config_unicode_path_segments = kw.get('unicode_path_segments', 't')
+ effective_unicode_path_segments = asbool(eget('BFG_UNICODE_PATH_SEGMENTS',
+ config_unicode_path_segments))
+ update = {
+ 'debug_authorization': effective_debug_all or effective_debug_auth,
+ 'debug_notfound': effective_debug_all or effective_debug_notfound,
+ 'reload_templates': effective_reload_templates,
+ 'unicode_path_segments': effective_unicode_path_segments,
+ }
+
+ kw.update(update)
+ return kw
+