INNER CODE UNIT · Python

_flatten_routes

stephenhillier/starlette_exporter · starlette_exporter/middleware.py:58

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
        if hasattr(starlette_route, "effective_route_contexts"):
            for route_context in starlette_route.effective_route_contexts():
                yield _matchable_route(route_context)
        else:
            # Starlette and FastAPI < 0.137.0
            yield starlette_route

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…