From ab6bac111c9fa551ae0b6386a2cd6a13b45c26c7 Mon Sep 17 00:00:00 2001 From: Armin Ronacher Date: Sun, 26 Jun 2011 21:34:27 +0200 Subject: [PATCH] Made it theoretically possible to hook into request matching --- flask/ctx.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/flask/ctx.py b/flask/ctx.py index 1e700a84..3ea43b97 100644 --- a/flask/ctx.py +++ b/flask/ctx.py @@ -90,12 +90,7 @@ class RequestContext(object): self.flashes = None self.session = None - try: - url_rule, self.request.view_args = \ - self.url_adapter.match(return_rule=True) - self.request.url_rule = url_rule - except HTTPException, e: - self.request.routing_exception = e + self.match_request() # Support for deprecated functionality. This is doing away with # Flask 1.0 @@ -107,6 +102,17 @@ class RequestContext(object): if bp is not None and blueprint_is_module(bp): self.request._is_old_module = True + def match_request(self): + """Can be overridden by a subclass to hook into the matching + of the request. + """ + try: + url_rule, self.request.view_args = \ + self.url_adapter.match(return_rule=True) + self.request.url_rule = url_rule + except HTTPException, e: + self.request.routing_exception = e + def push(self): """Binds the request context to the current context.""" _request_ctx_stack.push(self)