Fork of aspen.typecasting to clean some stuff up. Upstream it, ya?
cast(website, request, state)¶
Implement typecasting (differently from stock Aspen).
When matching paths, Aspen looks for
/%foo/and then foo is a variable with the value in the URL path, so
/bar/would end up with
There’s a dictionary at
website.typecastersthat maps variable names to functions, dependency-injectable as with
website.algorithm(state-chain) functions. If an entry exists in
typecastersfor a given path variable, then the value of
path[part]is replaced with the result of calling the function.
Before calling your cast function, we add an additional value to the state dict at
path_part: the URL path part that matched, as a string. That is user input, so handle it carefully. It’s your job to raise
Response(40x)if it’s bad input.