From 23ab84757a4d216a7c5eea77e85aedfd3a9400ca Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Wed, 30 Jun 2010 17:24:23 +0000 Subject: pass only match and route and document route minimally --- CHANGES.txt | 14 +++++++++----- repoze/bfg/urldispatch.py | 5 ++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 8eb1b57c7..3c1b35a6a 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -17,11 +17,10 @@ Features always ``None``. As of this release, the first argument passed to a predicate is now - a dictionary conventionally named ``info`` consisting of ``match``, - ``route``, and ``mapper``. ``match`` is a dictionary: it represents - the arguments matched in the URL by the route. ``route`` is an - object representing the route that matched. ``mapper`` is the url - dispatch route mapper object. + a dictionary conventionally named ``info`` consisting of ``route``, + and ``match``. ``match`` is a dictionary: it represents the + arguments matched in the URL by the route. ``route`` is an object + representing the route which was matched. This is useful when predicates need access to the route match. For example:: @@ -30,11 +29,16 @@ Features def predicate(info, request): if info['match'][segment_name] in args: return True + return predicate num_one_two_or_three = any_of('num, 'one', 'two', 'three') add_route('/:num', custom_predicates=(num_one_two_or_three,)) + The ``route`` object is an object that has two useful attributes: + ``name`` and ``path``. The ``name`` attribute is the route name. + The ``path`` attribute is the route pattern. + Documentation ------------- diff --git a/repoze/bfg/urldispatch.py b/repoze/bfg/urldispatch.py index 458f1a7a5..51b6f9f84 100644 --- a/repoze/bfg/urldispatch.py +++ b/repoze/bfg/urldispatch.py @@ -51,7 +51,10 @@ class RoutesMapper(object): match = route.match(path) if match is not None: preds = route.predicates - info = {'route':route, 'match':match} + # NB: it is the intent that only 'match' be relied on + # by built-in predicates. 'route' and 'mapper' may be + # used by custom predicates. + info = {'match':match, 'route':route} if preds and not all((p(info, request) for p in preds)): continue return info -- cgit v1.2.3