diff options
Diffstat (limited to 'pyramid/router.py')
| -rw-r--r-- | pyramid/router.py | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/pyramid/router.py b/pyramid/router.py index 4054ef52e..19773cf62 100644 --- a/pyramid/router.py +++ b/pyramid/router.py @@ -20,6 +20,7 @@ from pyramid.events import ( ContextFound, NewRequest, NewResponse, + BeforeTraversal, ) from pyramid.httpexceptions import HTTPNotFound @@ -114,10 +115,19 @@ class Router(object): root_factory = route.factory or self.root_factory + # Notify anyone listening that we are about to start traversal + # + # Notify before creating root_factory in case we want to do something + # special on a route we may have matched. See + # https://github.com/Pylons/pyramid/pull/1876 for ideas of what is + # possible. + has_listeners and notify(BeforeTraversal(request)) + + # Create the root factory root = root_factory(request) attrs['root'] = root - # find a context + # We are about to traverse and find a context traverser = adapters.queryAdapter(root, ITraverser) if traverser is None: traverser = ResourceTreeTraverser(root) @@ -133,6 +143,9 @@ class Router(object): ) attrs.update(tdict) + + # Notify anyone listening that we have a context and traversal is + # complete has_listeners and notify(ContextFound(request)) # find a view callable |
