- # No matching page?
- if route_match is None:
- # Try to do see if we have a match with a trailing slash
- # added and if so, redirect
- if not path_info.endswith('/') \
- and request.method == 'GET' \
- and self.routing.match(path_info + '/'):
- new_path_info = path_info + '/'
- if request.GET:
- new_path_info = '%s?%s' % (
- new_path_info, urllib.urlencode(request.GET))
- redirect = exc.HTTPFound(location=new_path_info)
- return request.get_response(redirect)(environ, start_response)
-
- # Okay, no matches. 404 time!
- request.matchdict = {} # in case our template expects it
- return render_404(request)(environ, start_response)
-
- controller = common.import_component(route_match['controller'])
+ try:
+ found_rule, url_values = map_adapter.match(return_rule=True)
+ request.matchdict = url_values
+ except HTTPException as exc:
+ # Stop and render exception
+ return render_http_exception(
+ request, exc,
+ exc.get_description(environ))(environ, start_response)
+
+ controller = endpoint_to_controller(found_rule)