- util.setup_user_in_request(request)
-
- # 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 util.render_404(request)(environ, start_response)
-
- controller = util.import_component(route_match['controller'])
+ request.locale = translate.get_locale_from_request(request)
+ request.template_env = template.get_jinja_env(
+ self.template_loader, request.locale)
+
+ def build_proxy(endpoint, **kw):
+ try:
+ qualified = kw.pop('qualified')
+ except KeyError:
+ qualified = False
+
+ return map_adapter.build(
+ endpoint,
+ values=dict(**kw),
+ force_external=qualified)
+
+ request.urlgen = build_proxy
+
+ mg_request.setup_user_in_request(request)
+
+ try:
+ found_rule, url_values = map_adapter.match(return_rule=True)
+ request.matchdict = url_values
+ except RequestRedirect as response:
+ # Deal with 301 responses eg due to missing final slash
+ return response(environ, start_response)
+ 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)
+
+ # pass the request through our meddleware classes
+ try:
+ for m in self.meddleware:
+ response = m.process_request(request, controller)
+ if response is not None:
+ return response(environ, start_response)
+ except HTTPException as e:
+ return render_http_exception(
+ request, e,
+ e.get_description(environ))(environ, start_response)
+