Typing
fasthx.HTMLRenderer = SyncHTMLRenderer[Tcontra] | AsyncHTMLRenderer[Tcontra]
module-attribute
Sync or async HTML renderer type.
fasthx.typing.SyncHTMLRenderer
Bases: Protocol[Tcontra]
Sync HTML renderer definition.
Source code in fasthx/typing.py
__call__(result, *, context, request)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result
|
Tcontra
|
The result of the route the renderer is used on. |
required |
context
|
dict[str, Any]
|
Every keyword argument the route received. |
required |
request
|
Request
|
The request being served. |
required |
Returns:
Type | Description |
---|---|
str | Response
|
HTML string (it will be automatically converted to |
Source code in fasthx/typing.py
fasthx.typing.AsyncHTMLRenderer
Bases: Protocol[Tcontra]
Async HTML renderer definition.
Source code in fasthx/typing.py
__call__(result, *, context, request)
async
Parameters:
Name | Type | Description | Default |
---|---|---|---|
result
|
Tcontra
|
The result of the route the renderer is used on. |
required |
context
|
dict[str, Any]
|
Every keyword argument the route received. |
required |
request
|
Request
|
The request being served. |
required |
Returns:
Type | Description |
---|---|
str | Response
|
HTML string (it will be automatically converted to |
Source code in fasthx/typing.py
fasthx.typing.RequestComponentSelector
Bases: Protocol[Tco]
Component selector protocol that uses the request to select the component that will be rendered.
The protocol is runtime-checkable, so it can be used in isinstance()
, issubclass()
calls.
Source code in fasthx/typing.py
get_component(request, error)
Returns the component that was requested by the client.
The caller should ensure that error
will be the exception that was raised by the
route or None
if the route returned normally.
If an implementation can not or does not want to handle route errors, then the method should re-raise the received exception. Example:
class MyComponentSelector:
def get_component(self, request: Request, error: Exception | None) -> str:
if error is not None:
raise error
...
Raises:
Type | Description |
---|---|
KeyError
|
If the component couldn't be identified. |
Exception
|
The received |
Source code in fasthx/typing.py
fasthx.typing.ComponentSelector: TypeAlias = T | RequestComponentSelector[T]
module-attribute
Type alias for known component selectors.