Functions
build_cascade_context
2
dict[str, Any]
▼
Run context providers from root to leaf, merging results.
Each provider's outp…
async
build_cascade_context
2
dict[str, Any]
▼
async def build_cascade_context(providers: tuple[ContextProvider, ...], path_params: dict[str, str]) -> dict[str, Any]
Run context providers from root to leaf, merging results.
Each provider's output is merged into the accumulated context. Later providers (deeper in the filesystem) override earlier ones.
Providers may raiseHTTPError subclasses (e.g. NotFound)
to abort the cascade early. The exception propagates to the
caller (page_wrapper), which is wrapped by handle_request
— chirp's standard error pipeline renders the appropriate error
page automatically. This eliminates the need for downstream
handlers to guard against missing resources::
# In _context.py:
from chirp import NotFound
def context(doc_id: str) -> dict:
doc = store.get(doc_id)
if doc is None:
raise NotFound(f"Document {doc_id} not found")
return {"doc": doc}
Parameters
| Name | Type | Description |
|---|---|---|
providers |
tuple[ContextProvider, ...] |
Context providers ordered from root (depth=0) to leaf. |
path_params |
dict[str, str] |
Extracted path parameters from the URL match. |
Returns
dict[str, Any]
_call_provider
2
Any
▼
Call a context provider, injecting matching path params.
The provider function…
_call_provider
2
Any
▼
def _call_provider(func: Any, path_params: dict[str, str]) -> Any
Call a context provider, injecting matching path params.
The provider function's signature determines which path params it receives::
async def context(doc_id: str) -> dict:
... # receives doc_id from /doc/{doc_id}/...
def context() -> dict:
... # receives nothing
Parameters
| Name | Type | Description |
|---|---|---|
func |
Any |
|
path_params |
dict[str, str] |
Returns
Any