MCPcopy
hub / github.com/fastapi/fastapi / matches

Method matches

fastapi/routing.py:1490–1511  ·  view source on GitHub ↗
(self, scope: Scope)

Source from the content-addressed store, hash-verified

1488 return context
1489
1490 def matches(self, scope: Scope) -> tuple[Match, Scope]:
1491 if isinstance(self.original_route, _FrontendRouteGroup):
1492 return self.original_route.matches_with_prefix(scope, self.frontend_prefix)
1493 if not isinstance(self.original_route, APIRoute):
1494 assert self.starlette_route is not None
1495 return self.starlette_route.matches(scope)
1496 if scope["type"] != "http":
1497 return Match.NONE, {}
1498 route_path = get_route_path(scope)
1499 match = self.path_regex.match(route_path)
1500 if not match:
1501 return Match.NONE, {}
1502 matched_params = match.groupdict()
1503 for key, value in matched_params.items():
1504 matched_params[key] = self.param_convertors[key].convert(value)
1505 path_params = dict(scope.get("path_params", {}))
1506 path_params.update(matched_params)
1507 child_scope = {"endpoint": self.endpoint, "path_params": path_params}
1508 methods = self.methods
1509 if methods and scope["method"] not in methods:
1510 return Match.PARTIAL, child_scope
1511 return Match.FULL, child_scope
1512
1513 def url_path_for(self, name: str, /, **path_params: Any) -> Any:
1514 if not isinstance(self.original_route, APIRoute):

Callers

nothing calls this directly

Calls 3

matches_with_prefixMethod · 0.80
matchesMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected