summaryrefslogtreecommitdiff
path: root/repoze/bfg/urldispatch.py
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-11-01 00:48:04 +0000
committerChris McDonough <chrism@agendaless.com>2009-11-01 00:48:04 +0000
commit65476e8d2cef6b3ce105c4786645a88151a09a6c (patch)
tree40d0c77df2fa1ba54c6bdb9df7effcc7a70049a9 /repoze/bfg/urldispatch.py
parent3052d0b41bd06314b0b1f1c78e9977b8174f637a (diff)
downloadpyramid-65476e8d2cef6b3ce105c4786645a88151a09a6c.tar.gz
pyramid-65476e8d2cef6b3ce105c4786645a88151a09a6c.tar.bz2
pyramid-65476e8d2cef6b3ce105c4786645a88151a09a6c.zip
- The ZCML ``route`` directive's attributes ``xhr``,
``request_method``, ``path_info``, ``request_param``, ``header`` and ``accept`` are now *route* predicates rather than *view* predicates. If one or more of these predicates is specified in the route configuration, all of the predicates must return true for the route to match a request. If one or more of the route predicates associated with a route returns ``False`` when checked during a request, the route match fails, and the next match in the routelist is tried. This differs from the previous behavior, where no route predicates existed and all predicates were considered view predicates, because in that scenario, the next route was not tried.
Diffstat (limited to 'repoze/bfg/urldispatch.py')
-rw-r--r--repoze/bfg/urldispatch.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/repoze/bfg/urldispatch.py b/repoze/bfg/urldispatch.py
index 4088cef12..185baa1a1 100644
--- a/repoze/bfg/urldispatch.py
+++ b/repoze/bfg/urldispatch.py
@@ -5,18 +5,20 @@ from zope.interface import directlyProvides
from repoze.bfg.interfaces import IRouteRequest
+from repoze.bfg.compat import all
+from repoze.bfg.encode import url_quote
from repoze.bfg.traversal import traversal_path
from repoze.bfg.traversal import quote_path_segment
-from repoze.bfg.encode import url_quote
_marker = object()
class Route(object):
- def __init__(self, path, name=None, factory=None):
+ def __init__(self, path, name=None, factory=None, predicates=()):
self.path = path
self.match, self.generate = _compile_route(path)
self.name = name
self.factory = factory
+ self.predicates = predicates
class RoutesRootFactory(object):
def __init__(self, default_root_factory):
@@ -30,8 +32,8 @@ class RoutesRootFactory(object):
def get_routes(self):
return self.routelist
- def connect(self, path, name, factory=None):
- route = Route(path, name, factory)
+ def connect(self, path, name, factory=None, predicates=()):
+ route = Route(path, name, factory, predicates)
self.routelist.append(route)
self.routes[name] = route
return route
@@ -69,6 +71,9 @@ class RoutesRootFactory(object):
for route in self.routelist:
match = route.match(path)
if match is not None:
+ preds = route.predicates
+ if preds and not all((p(None, request) for p in preds)):
+ continue
environ['wsgiorg.routing_args'] = ((), match)
environ['bfg.routes.route'] = route
environ['bfg.routes.matchdict'] = match