ContextRepo
faststream.utils.ContextRepo #
Bases: Singleton
A class to represent a context repository.
Initialize the class.
ATTRIBUTE | DESCRIPTION |
---|---|
_global_context | a dictionary representing the global context
|
_scope_context | a dictionary representing the scope context
|
Source code in faststream/utils/context/repository.py
set_global #
reset_global #
Resets a key in the global context.
PARAMETER | DESCRIPTION |
---|---|
key | The key to reset in the global context. TYPE: |
RETURNS | DESCRIPTION |
---|---|
None | None |
set_local #
Set a local context variable.
PARAMETER | DESCRIPTION |
---|---|
key | The key for the context variable. TYPE: |
value | The value to set for the context variable. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Token[Any] | Token[T]: A token representing the context variable. |
Source code in faststream/utils/context/repository.py
reset_local #
Resets the local context for a given key.
PARAMETER | DESCRIPTION |
---|---|
key | The key to reset the local context for. TYPE: |
tag | The tag associated with the local context. |
RETURNS | DESCRIPTION |
---|---|
None | None |
Source code in faststream/utils/context/repository.py
get_local #
Get the value of a local variable.
PARAMETER | DESCRIPTION |
---|---|
key | The key of the local variable to retrieve. TYPE: |
default | The default value to return if the local variable is not found. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Any | The value of the local variable. |
Source code in faststream/utils/context/repository.py
scope #
Sets a local variable and yields control to the caller. After the caller is done, the local variable is reset.
PARAMETER | DESCRIPTION |
---|---|
key | The key of the local variable TYPE: |
value | The value to set the local variable to TYPE: |
YIELDS | DESCRIPTION |
---|---|
None | None |
RETURNS | DESCRIPTION |
---|---|
Iterator[None] | An iterator that yields None |
Source code in faststream/utils/context/repository.py
get #
Get the value associated with a key.
PARAMETER | DESCRIPTION |
---|---|
key | The key to retrieve the value for. TYPE: |
default | The default value to return if the key is not found. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Any | The value associated with the key. |
Source code in faststream/utils/context/repository.py
resolve #
Resolve the context of an argument.
PARAMETER | DESCRIPTION |
---|---|
argument | A string representing the argument. TYPE: |
RETURNS | DESCRIPTION |
---|---|
Any | The resolved context of the argument. |
RAISES | DESCRIPTION |
---|---|
(AttributeError, KeyError) | If the argument does not exist in the context. |