Functions
build_cascade_context
3
dict[str, Any]
▼
Run context providers from root to leaf, merging results.
Each provider's outp…
async
build_cascade_context
3
dict[str, Any]
▼
async def build_cascade_context(providers: tuple[ContextProvider, ...], path_params: dict[str, str], service_providers: dict[type, Any] | None = None) -> 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. |
service_providers |
dict[type, Any] | None |
Type-keyed factories from None
|
Returns
dict[str, Any]
_call_provider
4
Any
▼
Call a context provider, injecting path params, parent context, and services.
…
_call_provider
4
Any
▼
def _call_provider(func: Any, path_params: dict[str, str], accumulated_ctx: dict[str, Any], service_providers: dict[type, Any]) -> Any
Call a context provider, injecting path params, parent context, and services.
The provider function's signature determines which arguments it receives:
-
Path params (e.g.
namefrom/skill/{name}) come from the URL. -
Other params come from the accumulated context of parent providers.
-
Params with type annotations matching
app.provide()are resolved from service providers::def context() -> dict:
... # receives nothingdef context(doc_id: str, store: DocumentStore) -> dict:
... # doc_id from path, store from app.provide()
Parameters
| Name | Type | Description |
|---|---|---|
func |
Any |
|
path_params |
dict[str, str] |
|
accumulated_ctx |
dict[str, Any] |
|
service_providers |
dict[type, Any] |
Returns
Any