From 6b7d2d57cf7484a56151c8632eeea150ece6fb90 Mon Sep 17 00:00:00 2001 From: Victor Lima Date: Wed, 15 Jan 2020 22:52:32 -0300 Subject: [PATCH 1/3] Added route value to scope --- starlette/routing.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/starlette/routing.py b/starlette/routing.py index 52ddcdf2e..e3bc332d4 100644 --- a/starlette/routing.py +++ b/starlette/routing.py @@ -196,7 +196,12 @@ def matches(self, scope: Scope) -> typing.Tuple[Match, Scope]: matched_params[key] = self.param_convertors[key].convert(value) path_params = dict(scope.get("path_params", {})) path_params.update(matched_params) - child_scope = {"endpoint": self.endpoint, "path_params": path_params} + child_scope = { + "endpoint": self.endpoint, + "path_params": path_params, + "route": self.path, + "name": self.name, + } if self.methods and scope["method"] not in self.methods: return Match.PARTIAL, child_scope else: From 5dc3170fa144539a044b1d241a93d08f89327336 Mon Sep 17 00:00:00 2001 From: Victor Lima Date: Wed, 29 Jan 2020 14:40:05 -0300 Subject: [PATCH 2/3] Added matched routes to scope --- starlette/routing.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/starlette/routing.py b/starlette/routing.py index e3bc332d4..42af40b1a 100644 --- a/starlette/routing.py +++ b/starlette/routing.py @@ -199,8 +199,6 @@ def matches(self, scope: Scope) -> typing.Tuple[Match, Scope]: child_scope = { "endpoint": self.endpoint, "path_params": path_params, - "route": self.path, - "name": self.name, } if self.methods and scope["method"] not in self.methods: return Match.PARTIAL, child_scope @@ -546,17 +544,20 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: partial = None + scope["routes"] = {"full": None, "partial": []} for route in self.routes: # Determine if any route matches the incoming scope, # and hand over to the matching route if found. match, child_scope = route.matches(scope) if match == Match.FULL: scope.update(child_scope) + scope["routes"]["full"] = route await route.handle(scope, receive, send) return elif match == Match.PARTIAL and partial is None: partial = route partial_scope = child_scope + scope["routes"]["partial"].append(route) if partial is not None: #  Handle partial matches. These are cases where an endpoint is From 61f0f7288cdaaf7e386e649e65c28684f6fd54cf Mon Sep 17 00:00:00 2001 From: Victor Lima Date: Mon, 24 Feb 2020 12:58:07 -0300 Subject: [PATCH 3/3] Updating routing format --- starlette/routing.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/starlette/routing.py b/starlette/routing.py index 42af40b1a..a35c93be1 100644 --- a/starlette/routing.py +++ b/starlette/routing.py @@ -544,20 +544,20 @@ async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None: partial = None - scope["routes"] = {"full": None, "partial": []} + scope["routes"] = [] for route in self.routes: # Determine if any route matches the incoming scope, # and hand over to the matching route if found. match, child_scope = route.matches(scope) if match == Match.FULL: scope.update(child_scope) - scope["routes"]["full"] = route + scope["routes"].append(route) await route.handle(scope, receive, send) return elif match == Match.PARTIAL and partial is None: partial = route partial_scope = child_scope - scope["routes"]["partial"].append(route) + scope["routes"].append(route) if partial is not None: #  Handle partial matches. These are cases where an endpoint is