Module: storage
- class omemo.storage.Just(value)[source]
Bases:
Maybe[ValueTypeT]A
Maybethat does hold a value.- Parameters:
value (ValueTypeT)
- from_just()[source]
- Return type:
TypeVar(ValueTypeT)- Returns:
The value if this is a
Just.- Raises:
NothingException – if this is a
Nothing.
- class omemo.storage.Maybe[source]
Bases:
ABC,Generic[ValueTypeT]typing’s Optional[A] is just an alias for Union[None, A], which means if A is a union itself that allows None, the Optional[A] doesn’t add anything. E.g. Optional[Optional[X]] = Optional[X] is true for any type X. This Maybe class actually differenciates whether a value is set or not.
All incoming and outgoing values or cloned using
copy.deepcopy(), such that values stored in a Maybe instance are not affected by outside application logic.- abstractmethod from_just()[source]
- Return type:
TypeVar(ValueTypeT)- Returns:
The value if this is a
Just.- Raises:
NothingException – if this is a
Nothing.
- class omemo.storage.Nothing[source]
Bases:
Maybe[ValueTypeT]A
Maybethat does not hold a value.- from_just()[source]
- Return type:
TypeVar(ValueTypeT)- Returns:
The value if this is a
Just.- Raises:
NothingException – if this is a
Nothing.
- exception omemo.storage.NothingException[source]
Bases:
ExceptionRaised by
Maybe.from_just(), in case theMaybeis aNothing.
- class omemo.storage.Storage(disable_cache=False)[source]
Bases:
ABCA simple key/value storage class with optional caching (on by default). Keys can be any Python string, values any JSON-serializable structure.
Warning
Writing (and deletion) operations must be performed right away, before returning from the method. Such operations must not be cached or otherwise deferred.
Warning
All parameters must be treated as immutable unless explicitly noted otherwise.
Note
The
Maybetype performs the additional job of cloning stored and returned values, which essential to decouple the cached values from the application logic.- Parameters:
disable_cache (bool)
- __init__(disable_cache=False)[source]
Configure caching behaviour of the storage.
- Parameters:
disable_cache (
bool) – Whether to disable the cache, which is on by default. Use this parameter if your storage implementation handles caching itself, to avoid pointless double caching.
- abstractmethod async _load(key)[source]
Load a value.
- Parameters:
key (
str) – The key identifying the value.- Return type:
Maybe[JSONType]- Returns:
The loaded value, if it exists.
- Raises:
StorageException – if any kind of storage operation failed. Feel free to raise a subclass instead.
- abstractmethod async _store(key, value)[source]
Store a value.
- Parameters:
key (
str) – The key identifying the value.value (JSONType) – The value to store under the given key.
- Raises:
StorageException – if any kind of storage operation failed. Feel free to raise a subclass instead.
- Return type:
- abstractmethod async _delete(key)[source]
Delete a value, if it exists.
- Parameters:
key (
str) – The key identifying the value to delete.- Raises:
StorageException – if any kind of storage operation failed. Feel free to raise a subclass instead. Do not raise if the key doesn’t exist.
- Return type:
- async load(key)[source]
Load a value.
- Parameters:
key (
str) – The key identifying the value.- Return type:
Maybe[JSONType]- Returns:
The loaded value, if it exists.
- Raises:
StorageException – if any kind of storage operation failed. Forwarded from
_load().
- async store(key, value)[source]
Store a value.
- Parameters:
key (
str) – The key identifying the value.value (JSONType) – The value to store under the given key.
- Raises:
StorageException – if any kind of storage operation failed. Forwarded from
_store().- Return type:
- async delete(key)[source]
Delete a value, if it exists.
- Parameters:
key (
str) – The key identifying the value to delete.- Raises:
StorageException – if any kind of storage operation failed. Does not raise if the key doesn’t exist. Forwarded from
_delete().- Return type:
- async store_bytes(key, value)[source]
Variation of
store()for storing specifically bytes values.- Parameters:
- Raises:
StorageException – if any kind of storage operation failed. Forwarded from
_store().- Return type:
- async load_primitive(key, primitive)[source]
Variation of
load()for loading specifically primitive values.- Parameters:
- Return type:
- Returns:
The loaded and type-checked value, if it exists.
- Raises:
StorageException – if any kind of storage operation failed. Forwarded from
_load().
- async load_bytes(key)[source]
Variation of
load()for loading specifically bytes values.- Parameters:
key (
str) – The key identifying the value.- Return type:
- Returns:
The loaded and type-checked value, if it exists.
- Raises:
StorageException – if any kind of storage operation failed. Forwarded from
_load().
- async load_optional(key, primitive)[source]
Variation of
load()for loading specifically optional primitive values.
- async load_list(key, primitive)[source]
Variation of
load()for loading specifically lists of primitive values.
- async load_dict(key, primitive)[source]
Variation of
load()for loading specifically dictionaries of primitive values.
- exception omemo.storage.StorageException[source]
Bases:
OMEMOExceptionParent type for all exceptions specifically raised by methods of
Storage.
- class omemo.storage.ValueTypeT
alias of TypeVar(‘ValueTypeT’)