From 8cfe7068783a3520aa3bc09f260502d002e9ac60 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sun, 25 Jan 2009 20:52:35 +0000 Subject: - The ``repoze.bfg.urldispatch.RoutesRootFactory`` now injects the ``wsgiorg.routing_args`` environment variable into the environ when a route matches. This is a tuple of ((), routing_args) where routing_args is the value that comes back from the routes mapper match (the "match dict"). - The ``repoze.bfg.traversal.RoutesModelTraverser`` class now wants to obtain the ``view_name`` and ``subpath`` from the ``wsgiorgs.routing_args`` environment variable. It falls back to obtaining these from the context for backwards compatibility. --- repoze/bfg/traversal.py | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) (limited to 'repoze/bfg/traversal.py') diff --git a/repoze/bfg/traversal.py b/repoze/bfg/traversal.py index d3befe86c..2d56f9302 100644 --- a/repoze/bfg/traversal.py +++ b/repoze/bfg/traversal.py @@ -172,9 +172,28 @@ class RoutesModelTraverser(object): self.context = context def __call__(self, environ): - view_name = getattr(self.context, 'controller', None) # b/w compat<0.6.3 - if view_name is None: - view_name = getattr(self.context, 'view_name', '') # 0.6.3+ - subpath = getattr(self.context, 'subpath', '') # 0.6.3+ - subpath = filter(None, subpath.split('/')) + # the traverser *wants* to get routing args from the environ + # as of 0.6.5; the rest of this stuff is for backwards + # compatibility + try: + # 0.6.5 + + routing_args = environ['wsgiorg.routing_args'][1] + except KeyError: + # <= 0.6.4 + routing_args = self.context.__dict__ + try: + view_name = routing_args['view_name'] + except KeyError: + # b/w compat < 0.6.3 + try: + view_name = routing_args['controller'] + except KeyError: + view_name = '' + try: + subpath = routing_args['subpath'] + subpath = filter(None, subpath.split('/')) + except KeyError: + # b/w compat < 0.6.5 + subpath = [] + return self.context, view_name, subpath -- cgit v1.2.3