peyk.fsm.storage.base¶
Storage contracts and key builders for the dispatcher FSM.
Functions
|
Convert a legacy string key while preserving old storage tests. |
Classes
|
Abstract asynchronous FSM storage keyed by |
|
Build aiogram-shaped FSM keys with platform and bot namespaces. |
|
Build backend keys from a |
|
Adapt the pre-Phase-8 string-key storage API to |
|
Protocol for the pre-Phase-8 string-key storage API. |
|
Identify one FSM namespace without embedding a bot token. |
- class peyk.fsm.storage.base.StorageKey(platform: str, bot_id: int | str, chat_id: int | str | None, user_id: int | str | None, destiny: str = 'default')[source]¶
Bases:
objectIdentify one FSM namespace without embedding a bot token.
platformis deliberately part of the identity so equal numeric IDs on Telegram and Bale cannot share state.bot_idisolates two bots on the same platform.- platform: str¶
- bot_id: int | str¶
- chat_id: int | str | None¶
- user_id: int | str | None¶
- destiny: str¶
- class peyk.fsm.storage.base.KeyBuilder(*args, **kwargs)[source]¶
Bases:
ProtocolBuild backend keys from a
StorageKey.- build(key: StorageKey, part: str | None = None) str[source]¶
Performs the build operation for the FSM client.
- Parameters:
key – Value used by this operation.
part – Value used by this operation.
- Returns:
Result produced by the FSM operation.
- class peyk.fsm.storage.base.DefaultKeyBuilder(prefix: str = 'peyk', separator: str = ':', with_bot_id: bool = True, with_destiny: bool = True)[source]¶
Bases:
objectBuild aiogram-shaped FSM keys with platform and bot namespaces.
The default is equivalent to aiogram’s
with_bot_id=Trueplus the additional platform segment required by Peyk’s multi-platform contract.- prefix: str¶
- separator: str¶
- with_bot_id: bool¶
- with_destiny: bool¶
- build(key: StorageKey, part: str | None = None) str[source]¶
Performs the build operation for the FSM client.
- Parameters:
key – Value used by this operation.
part – Value used by this operation.
- Returns:
Result produced by the FSM operation.
- peyk.fsm.storage.base.coerce_storage_key(key: StorageKey | str) StorageKey[source]¶
Convert a legacy string key while preserving old storage tests.
New dispatcher code always passes
StorageKey; string keys are a deprecated compatibility escape hatch and cannot provide bot isolation.
- class peyk.fsm.storage.base.BaseStorage(*, key_builder: KeyBuilder | None = None)[source]¶
Bases:
ABCAbstract asynchronous FSM storage keyed by
StorageKey.- abstractmethod async get_state(key: StorageKey | str) str | None[source]¶
Retrieves state from the FSM API.
- Parameters:
key – Value used by this operation.
- Returns:
Result produced by the FSM operation.
- abstractmethod async set_state(key: StorageKey | str, state: str | None) None[source]¶
Updates state through the FSM API.
- Parameters:
key – Value used by this operation.
state – Value used by this operation.
- abstractmethod async get_data(key: StorageKey | str) dict[str, object][source]¶
Retrieves data from the FSM API.
- Parameters:
key – Value used by this operation.
- Returns:
Result produced by the FSM operation.
- abstractmethod async set_data(key: StorageKey | str, data: Mapping[str, object]) None[source]¶
Updates data through the FSM API.
- Parameters:
key – Value used by this operation.
data – Value used by this operation.
- abstractmethod async update_data(key: StorageKey | str, data: Mapping[str, object] | None = None, **kwargs: object) dict[str, object][source]¶
Performs the update data operation for the FSM client.
- Parameters:
key – Value used by this operation.
data – Value used by this operation.
- Returns:
Result produced by the FSM operation.
- class peyk.fsm.storage.base.LegacyStringStorage(*args, **kwargs)[source]¶
Bases:
ProtocolProtocol for the pre-Phase-8 string-key storage API.
- async get_state(key: str) str | None[source]¶
Retrieves state from the FSM API.
- Parameters:
key – Value used by this operation.
- Returns:
Result produced by the FSM operation.
- async set_state(key: str, state: str | None) None[source]¶
Updates state through the FSM API.
- Parameters:
key – Value used by this operation.
state – Value used by this operation.
- async get_data(key: str) dict[str, object][source]¶
Retrieves data from the FSM API.
- Parameters:
key – Value used by this operation.
- Returns:
Result produced by the FSM operation.
- async set_data(key: str, data: Mapping[str, object]) None[source]¶
Updates data through the FSM API.
- Parameters:
key – Value used by this operation.
data – Value used by this operation.
- class peyk.fsm.storage.base.LegacyStorageAdapter(storage: LegacyStringStorage, *, key_builder: KeyBuilder | None = None)[source]¶
Bases:
BaseStorageAdapt the pre-Phase-8 string-key storage API to
StorageKey.- async get_state(key: StorageKey | str) str | None[source]¶
Retrieves state from the FSM API.
- Parameters:
key – Value used by this operation.
- Returns:
Result produced by the FSM operation.
- async set_state(key: StorageKey | str, state: str | None) None[source]¶
Updates state through the FSM API.
- Parameters:
key – Value used by this operation.
state – Value used by this operation.
- async get_data(key: StorageKey | str) dict[str, object][source]¶
Retrieves data from the FSM API.
- Parameters:
key – Value used by this operation.
- Returns:
Result produced by the FSM operation.
- async set_data(key: StorageKey | str, data: Mapping[str, object]) None[source]¶
Updates data through the FSM API.
- Parameters:
key – Value used by this operation.
data – Value used by this operation.
- async update_data(key: StorageKey | str, data: Mapping[str, object] | None = None, **kwargs: object) dict[str, object][source]¶
Performs the update data operation for the FSM client.
- Parameters:
key – Value used by this operation.
data – Value used by this operation.
- Returns:
Result produced by the FSM operation.