diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-01-11 02:20:52 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-01-11 02:20:52 +0000 |
| commit | 358dc276d28fb395a9a742ff53dc66ee115c58ad (patch) | |
| tree | c92dd9bdd24f4b473a7e56a7a498aac046dd4ed4 /repoze/bfg/router.py | |
| parent | be268487581bf94086ecc18904113d71237612e1 (diff) | |
| download | pyramid-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/router.py')
| -rw-r--r-- | repoze/bfg/router.py | 54 |
1 files changed, 35 insertions, 19 deletions
diff --git a/repoze/bfg/router.py b/repoze/bfg/router.py index 89101cb5e..a67cd1088 100644 --- a/repoze/bfg/router.py +++ b/repoze/bfg/router.py @@ -1,8 +1,11 @@ +import sys from cgi import escape from zope.component import getAdapter +from zope.component import getUtility from zope.component import queryUtility from zope.component.event import dispatch + from zope.interface import directlyProvides from zope.interface import implements @@ -18,10 +21,14 @@ from repoze.bfg.interfaces import ILogger from repoze.bfg.interfaces import ITraverserFactory from repoze.bfg.interfaces import IRequest from repoze.bfg.interfaces import IRouter +from repoze.bfg.interfaces import IRootFactory from repoze.bfg.interfaces import ISettings +from repoze.bfg.log import make_stream_logger + from repoze.bfg.registry import registry_manager from repoze.bfg.registry import makeRegistry +from repoze.bfg.settings import Settings from repoze.bfg.view import render_view_to_response from repoze.bfg.view import view_execution_permitted @@ -34,8 +41,7 @@ class Router(object): implements(IRouter) - def __init__(self, root_policy, registry): - self.root_policy = root_policy + def __init__(self, registry): self.registry = registry def __call__(self, environ, start_response): @@ -43,9 +49,10 @@ class Router(object): request = Request(environ) directlyProvides(request, IRequest) dispatch(NewRequest(request)) - root = self.root_policy(environ) + + root_factory = getUtility(IRootFactory) + root = root_factory(environ) traverser = getAdapter(root, ITraverserFactory) - settings = queryUtility(ISettings) context, name, subpath = traverser(environ) request.root = root @@ -54,6 +61,8 @@ class Router(object): request.subpath = subpath permitted = view_execution_permitted(context, request, name) + + settings = queryUtility(ISettings) debug_authorization = settings and settings.debug_authorization if debug_authorization: @@ -93,21 +102,29 @@ class Router(object): start_response(response.status, response.headerlist) return response.app_iter -def make_app(root_policy, package=None, filename='configure.zcml', +def make_app(root_factory, package=None, filename='configure.zcml', options=None): - """ Create a view registry based on the application's ZCML. and - return a Router object, representing a ``repoze.bfg`` WSGI - application. ``root_policy`` must be a callable that accepts a - WSGI environment and returns a graph root object. ``package`` is - a Python module representing the application's package, - ``filename`` is the filesystem path to a ZCML file (optionally - relative to the package path) that should be parsed to create the - view registry. ``options``, if used, should be a dictionary - containing bfg-specific runtime options, with each key - representing the option and the key's value representing the - specific option value, e.g. ``{'reload_templates':True}``""" - registry = makeRegistry(filename, package, options) - app = Router(root_policy, registry) + """ Return a Router object, representing a ``repoze.bfg`` WSGI + application. ``root_factory`` must be a callable that accepts a + WSGI environment and returns a root object. ``package`` is a + Python module representing the application's package, ``filename`` + is the filesystem path to a ZCML file (optionally relative to the + package path) that should be parsed to create the application + registry. ``options``, if used, should be a dictionary containing + runtime options (e.g. the key/value pairs in an app section of a + PasteDeploy file), with each key representing the option and the + key's value representing the specific option value, + e.g. ``{'reload_templates':True}``""" + if options is None: + options = {} + + registry = makeRegistry(filename, package) + settings = Settings(options) + registry.registerUtility(settings, ISettings) + debug_logger = make_stream_logger('repoze.bfg.debug', sys.stderr) + registry.registerUtility(debug_logger, ILogger, 'repoze.bfg.debug') + registry.registerUtility(root_factory, IRootFactory) + app = Router(registry) try: registry_manager.set(registry) @@ -117,4 +134,3 @@ def make_app(root_policy, package=None, filename='configure.zcml', return app - |
