Utils
- class falcon_auth2.RequestAttributes(req: Request, resp: Response, resource: Any, params: Mapping[str, Any], is_async: bool)[source]
Named tuple that is passed to the backend
authenticate()when a request is performed.- req: Request
The falcon request.
- resp: Response
The falcon response.
- resource: Any
The falcon responder resource.
- params: Mapping[str, Any]
The parameters of passed in the url.
- is_async: bool
Indicates that authenticate is running in async mode.
Async utilities
- async falcon_auth2.utils.greenlet_spawn(fn: ~collections.abc.Callable[[~_P], ~falcon_auth2.utils.asyncio_compat._T], *args: ~typing.~_P, **kwargs: ~typing.~_P) _T[source]
Runs a sync function
fnin a new greenlet.The sync function can then use
await_()to wait for async functions.- Parameters:
fn (Callable) – The sync callable to call.
*args – Positional arguments to pass to the
fncallable.**kwargs – Keyword arguments to pass to the
fncallable.
- Returns:
Any – The return value of
fnor raises an exception if it raised one.
- falcon_auth2.utils.await_(awaitable: Awaitable[_T]) _T[source]
Awaits an async function in a sync method.
The sync method must be insice a
greenlet_spawn()context.await_()calls cannot be nested.- Parameters:
awaitable (Awaitable) – The awaitable to call.
- Raises:
RuntimeError – If
await_was called outside agreenlet_spawn()context or nested in anotherawait_call.- Returns:
Any – The return value of
awaitableor raises an exception if it raised one.
- falcon_auth2.utils.call_maybe_async(support_async: bool, function_is_async: bool | None, err_msg: str, function: ~collections.abc.Callable[[~_P], ~falcon_auth2.utils.functions._T], *args: ~typing.~_P, **kwargs: ~typing.~_P) tuple[_T, bool][source]
Calls a function and waits for the result if it is async.
- Parameters:
support_async (bool) – Can run async cuntions.
function_is_async (Optional[bool]) – If the function is async. This function will determine if
functionis async when this parameter isNone.err_msg (str) – Name of the function. Used in case of error.
function (Callable) – The function to call.
*args – Positional arguments to pass to the
functioncallable.**kwargs – Keyword arguments to pass to the
functioncallable.
- Raises:
TypeError – if
functionis async andsupport_async=False.- Returns:
Tuple[Any, bool] – Returns the result and whatever the function is async.