diff options
| author | Chris McDonough <chrism@agendaless.com> | 2009-10-30 19:38:41 +0000 |
|---|---|---|
| committer | Chris McDonough <chrism@agendaless.com> | 2009-10-30 19:38:41 +0000 |
| commit | acc7765a037983907d3275312396ee10b6b9ad2e (patch) | |
| tree | dc91f45c5b638f6c86ec9c74b627e37251707d7c /repoze | |
| parent | 11644e705834ff65cb8963333855a1db6272ae1e (diff) | |
| download | pyramid-acc7765a037983907d3275312396ee10b6b9ad2e.tar.gz pyramid-acc7765a037983907d3275312396ee10b6b9ad2e.tar.bz2 pyramid-acc7765a037983907d3275312396ee10b6b9ad2e.zip | |
- The ``__call__`` of a plugin "traverser" implementation (registered
as an adapter for ``ITraverser`` or ``ITraverserFactory``) will now
receive a *request* as the single argument to its ``__call__``
method. In previous versions it was passed a WSGI ``environ``
object. The request object passed to the factory implements
dictionary-like methods in such a way that existing traverser code
which expects to be passed an environ will continue to work.
- Fix docs.
Diffstat (limited to 'repoze')
| -rw-r--r-- | repoze/bfg/router.py | 6 | ||||
| -rw-r--r-- | repoze/bfg/tests/test_router.py | 2 | ||||
| -rw-r--r-- | repoze/bfg/traversal.py | 19 |
3 files changed, 20 insertions, 7 deletions
diff --git a/repoze/bfg/router.py b/repoze/bfg/router.py index 3916d6627..c48a96664 100644 --- a/repoze/bfg/router.py +++ b/repoze/bfg/router.py @@ -71,7 +71,7 @@ class Router(object): traverser = registry.queryAdapter(root, ITraverser) if traverser is None: traverser = ModelGraphTraverser(root) - tdict = traverser(environ) + tdict = traverser(request) context, view_name, subpath, traversed, vroot, vroot_path = ( tdict['context'], tdict['view_name'], tdict['subpath'], tdict['traversed'], tdict['virtual_root'], @@ -136,8 +136,8 @@ def make_app(root_factory, package=None, filename='configure.zcml', """ Return a Router object, representing a fully configured ``repoze.bfg`` WSGI application. - ``root_factory`` must be a callable that accepts a WSGI - environment and returns a traversal root object. The traversal + ``root_factory`` must be a callable that accepts a :term:`request` + object and which returns a traversal root object. The traversal root returned by the root factory is the *default* traversal root; it can be overridden on a per-view basis. ``root_factory`` may be ``None``, in which case a 'default default' traversal root is diff --git a/repoze/bfg/tests/test_router.py b/repoze/bfg/tests/test_router.py index d2fbf4b2d..ac77508ef 100644 --- a/repoze/bfg/tests/test_router.py +++ b/repoze/bfg/tests/test_router.py @@ -46,7 +46,7 @@ class TestRouter(unittest.TestCase): def __init__(self, root): self.root = root - def __call__(self, path): + def __call__(self, request): values = {'root':self.root, 'context':context, 'view_name':view_name, diff --git a/repoze/bfg/traversal.py b/repoze/bfg/traversal.py index 43adcdebb..d48627e7e 100644 --- a/repoze/bfg/traversal.py +++ b/repoze/bfg/traversal.py @@ -268,12 +268,12 @@ def traverse(model, path): if path and path[0] == '/': model = find_root(model) - environ = {'PATH_INFO':path} + request = FakeRequest({'PATH_INFO':path}) traverser = queryAdapter(model, ITraverser) if traverser is None: traverser = ModelGraphTraverser(model) - return traverser(environ) + return traverser(request) def model_path_tuple(model, *elements): """ @@ -474,7 +474,15 @@ class ModelGraphTraverser(object): def __init__(self, root): self.root = root - def __call__(self, environ): + def __call__(self, request): + try: + environ = request.environ + except AttributeError: + # In BFG 1.0 and before, this API expected an environ + # rather than a request; some bit of code may still be + # passing us an environ. If so, deal. + environ = request + if 'bfg.routes.matchdict' in environ: matchdict = environ['bfg.routes.matchdict'] @@ -623,3 +631,8 @@ class TraversalContextURL(object): def _join_path_tuple(tuple): return tuple and '/'.join([quote_path_segment(x) for x in tuple]) or '/' +class FakeRequest(dict): + def __init__(self, environ): + self.update(environ) + self.environ = self # XXX circref? + |
