MCPcopy Index your code
hub / github.com/fastapi/fastapi / _FrontendRouteGroup

Class _FrontendRouteGroup

fastapi/routing.py:2062–2207  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2060
2061
2062class _FrontendRouteGroup(BaseRoute):
2063 def __init__(
2064 self,
2065 *,
2066 dependencies: Sequence[params.Depends] | None = None,
2067 dependency_overrides_provider: Any | None = None,
2068 ) -> None:
2069 self.routes: list[_FrontendRoute] = []
2070 self.dependencies = list(dependencies or [])
2071 self.dependency_overrides_provider = dependency_overrides_provider
2072 (
2073 self.dependant,
2074 self._flat_dependant,
2075 self._embed_body_fields,
2076 ) = _build_dependant_with_parameterless_dependencies(
2077 path="",
2078 call=_frontend_dependency_endpoint,
2079 dependencies=self.dependencies,
2080 )
2081
2082 def add_frontend_route(
2083 self,
2084 path: str,
2085 *,
2086 directory: str | os.PathLike[str],
2087 fallback: Literal["auto", "index.html", "404.html"] | None = "auto",
2088 check_dir: bool = True,
2089 ) -> None:
2090 self.routes.append(
2091 _FrontendRoute(
2092 path,
2093 directory=directory,
2094 fallback=fallback,
2095 check_dir=check_dir,
2096 )
2097 )
2098
2099 def matches(self, scope: Scope) -> tuple[Match, Scope]:
2100 match, child_scope, _ = self._match(scope, prefix="")
2101 return match, child_scope
2102
2103 def matches_with_prefix(self, scope: Scope, prefix: str) -> tuple[Match, Scope]:
2104 match, child_scope, _ = self._match(scope, prefix=prefix)
2105 return match, child_scope
2106
2107 def _match(
2108 self, scope: Scope, *, prefix: str
2109 ) -> tuple[Match, Scope, _FrontendRoute | None]:
2110 full: tuple[Scope, _FrontendRoute, int] | None = None
2111 partial: tuple[Scope, _FrontendRoute, int] | None = None
2112 for route in self.routes:
2113 path = _join_frontend_paths(prefix, route.path)
2114 match, child_scope = route.matches_with_path(scope, path)
2115 specificity = _frontend_path_specificity(path)
2116 if match == Match.FULL:
2117 if full is None or specificity > full[2]:
2118 full = (child_scope, route, specificity)
2119 elif match == Match.PARTIAL:

Callers 1

frontendMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…