Permalink
Browse files

Reversed the priority to match the last added route when multiple routes

have the same placeholder requirements.
  • Loading branch information...
1 parent 9796459 commit 7ecc829f5a78e2a04a64cc9a44d46a151b171554 @mmerickel mmerickel committed Aug 21, 2011
Showing with 5 additions and 4 deletions.
  1. +1 −1 pyramid/tests/test_urldispatch.py
  2. +4 −3 pyramid/urldispatch.py
@@ -178,7 +178,7 @@ def test_match_ordering(self):
group.add(route1)
path, kw = group.gen(request, (), {'a':1, 'b':2, 'c':3})
- self.assertEqual(path, '/p/1/2/3')
+ self.assertEqual(path, '/1/2/3')
self.assertEqual(kw, {'a':1, 'b':2, 'c':3})
class RoutesMapperTests(unittest.TestCase):
View
@@ -52,7 +52,7 @@ def __init__(self, name):
self.routes = []
self.sorted_routes = []
- def _match_route(self, request, elements, kw):
+ def _find_best_match(self, request, elements, kw):
""" Compare the provided keys to the required args of a route.
The selected route is the first one with all required keys satisfied.
@@ -71,7 +71,7 @@ def _match_route(self, request, elements, kw):
'provided keys "%s"' % (self.name, sorted(keys)))
def gen(self, request, elements, kw):
- route, elements, kw = self._match_route(request, elements, kw)
+ route, elements, kw = self._find_best_match(request, elements, kw)
path = route.generate(kw)
@@ -89,7 +89,8 @@ def add(self, route):
args = frozenset(route.args)
# -len(args) sorts routes in descending order by the number of args
- entry = (-len(args), next(self.counter), args, route)
+ # -next(self.counter) sorts routes in reverse order of adding
+ entry = (-len(args), -next(self.counter), args, route)
insort(self.sorted_routes, entry)
class RoutesMapper(object):

0 comments on commit 7ecc829

Please sign in to comment.