MCPcopy
hub / github.com/fastapi/fastapi / _IncludedRouter

Class _IncludedRouter

fastapi/routing.py:1571–1790  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1569
1570@dataclass
1571class _IncludedRouter(BaseRoute):
1572 original_router: "APIRouter"
1573 include_context: _RouterIncludeContext
1574 _effective_candidates: list["_EffectiveRouteContext | _IncludedRouter"] = field(
1575 default_factory=list
1576 )
1577 _effective_candidates_version: int | None = None
1578 _effective_low_priority_routes: list["_EffectiveRouteContext"] = field(
1579 default_factory=list
1580 )
1581 _effective_low_priority_routes_version: int | None = None
1582
1583 def effective_candidates(self) -> list["_EffectiveRouteContext | _IncludedRouter"]:
1584 routes_version = self.original_router._get_routes_version()
1585 if routes_version == self._effective_candidates_version:
1586 return self._effective_candidates
1587 self._effective_candidates = []
1588 candidates = self.original_router.routes
1589 for route in candidates:
1590 if isinstance(route, _IncludedRouter):
1591 child_context = self.include_context.combine(route.include_context)
1592 child_branch = _IncludedRouter(
1593 original_router=route.original_router,
1594 include_context=child_context,
1595 )
1596 self._effective_candidates.append(child_branch)
1597 continue
1598 route_context = self._build_effective_context(route)
1599 if route_context is not None:
1600 self._effective_candidates.append(route_context)
1601 self._effective_candidates_version = routes_version
1602 return self._effective_candidates
1603
1604 def effective_low_priority_routes(self) -> list["_EffectiveRouteContext"]:
1605 routes_version = self.original_router._get_routes_version()
1606 if routes_version == self._effective_low_priority_routes_version:
1607 return self._effective_low_priority_routes
1608 self._effective_low_priority_routes = []
1609 for route in self.original_router._low_priority_routes:
1610 route_context = self._build_effective_context(route)
1611 if route_context is not None:
1612 self._effective_low_priority_routes.append(route_context)
1613 for route in self.original_router.routes:
1614 if isinstance(route, _IncludedRouter):
1615 child_context = self.include_context.combine(route.include_context)
1616 child_branch = _IncludedRouter(
1617 original_router=route.original_router,
1618 include_context=child_context,
1619 )
1620 self._effective_low_priority_routes.extend(
1621 child_branch.effective_low_priority_routes()
1622 )
1623 self._effective_low_priority_routes_version = routes_version
1624 return self._effective_low_priority_routes
1625
1626 def _build_effective_context(
1627 self, route: BaseRoute
1628 ) -> _EffectiveRouteContext | None:

Callers 3

effective_candidatesMethod · 0.85
include_routerMethod · 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…