INNER CODE UNIT · Python

_matchable_route

stephenhillier/starlette_exporter · starlette_exporter/middleware.py:51

def _matchable_route(route: Any) -> BaseRoute:
    """
    Return the synthesized Starlette route from a FastAPI route context.
    """
    return getattr(route, "starlette_route", None) or route


def _flatten_routes(routes: Sequence[BaseRoute]) -> Iterator[BaseRoute]:
    """
    Yield the matchable routes from an app's route list.
    """
    if iter_route_contexts is not None:
        # FastAPI >0.137.2
        for route_context in iter_route_contexts(routes):
            yield _matchable_route(route_context)
        return
    for starlette_route in routes:
        # FastAPI >=0.137.0, <1.37.2

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…