fleche.storage.base
Attributes
Exceptions
Common base class for all non-exit exceptions. |
|
Inappropriate argument value (of correct type). |
Classes
Abstract base providing key-management helpers for any keyed storage. |
|
Primitive backend interface for key-value storage. |
|
Abstract domain interface for value storage. |
|
Bridges |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
Helper class that provides a standard way to create an ABC using |
|
Mixin that recursively destructures collections on save/load. |
|
Abstract domain interface for call storage. |
|
Bridges |
Module Contents
- exception fleche.storage.base.SaveError[source]
Bases:
ExceptionCommon base class for all non-exit exceptions.
- exception fleche.storage.base.AmbiguousDigestError[source]
Bases:
ValueErrorInappropriate argument value (of correct type).
- class fleche.storage.base.KeyManagement[source]
Bases:
abc.ABCAbstract base providing key-management helpers for any keyed storage.
Subclasses must implement
list,_evict, and_contains. The concrete helpersevict,contains,expand, andshrinkare implemented here once and inherited by all storage classes.- abstractmethod list() Iterable[fleche.digest.Digest][source]
- abstractmethod _evict(key: fleche.digest.Digest) None[source]
- abstractmethod _contains(key: fleche.digest.Digest) bool[source]
- evict(key: fleche.digest.Digest | str) None[source]
Removes the entry corresponding to the key from the storage.
- contains(key: fleche.digest.Digest | str) bool[source]
- expand(key: fleche.digest.Digest | str) fleche.digest.Digest[source]
Expands a short-hand digest to the full length one.
- shrink(key: fleche.digest.Digest | str) fleche.digest.Digest[source]
Find the shortest substring that is still an unambiguous reference to the same value.
- class fleche.storage.base.StorageBackend[source]
Bases:
KeyManagementPrimitive backend interface for key-value storage.
Backends implement the low-level
put/get/_evict/listoperations. Higher-level classes (ValueMixin,CallMixin) add domain-specific logic on top.- abstractmethod put(value: Any, key: fleche.digest.Digest) fleche.digest.Digest[source]
- abstractmethod get(key: fleche.digest.Digest) Any[source]
- _contains(key: fleche.digest.Digest) bool[source]
- class fleche.storage.base.ValueStorage[source]
Bases:
KeyManagementAbstract domain interface for value storage.
- abstractmethod save(value: Any, key: fleche.digest.Digest | None = None) fleche.digest.Digest[source]
- abstractmethod load(key: fleche.digest.Digest | str) Any[source]
- class fleche.storage.base.ValueMixin[source]
Bases:
ValueStorage,StorageBackendBridges
ValueStoragewithStorageBackendprimitives.Implements
saveandloadusingputandget. Concrete classes inherit from this and aStorageBackendimplementation to get a fully functional value storage.- save(value: Any, key: fleche.digest.Digest | None = None) fleche.digest.Digest[source]
- load(key: fleche.digest.Digest | str) Any[source]
- class fleche.storage.base.Digested[source]
Bases:
abc.ABCHelper class that provides a standard way to create an ABC using inheritance.
- abstractmethod underlying()[source]
Return plain underlying value, ie. list/dict/etc of nested values or their partial digests
- abstractmethod mend(storage: DestructuringMixin)[source]
- class fleche.storage.base.DigestedIterable[source]
Bases:
DigestedHelper class that provides a standard way to create an ABC using inheritance.
- underlying()[source]
Return plain underlying value, ie. list/dict/etc of nested values or their partial digests
- mend(storage: DestructuringMixin) list | tuple[source]
- class fleche.storage.base.DigestedDict[source]
Bases:
DigestedHelper class that provides a standard way to create an ABC using inheritance.
- underlying()[source]
Return plain underlying value, ie. list/dict/etc of nested values or their partial digests
- mend(storage: DestructuringMixin) dict[source]
- class fleche.storage.base.DestructuringMixin[source]
Bases:
StorageBackendMixin that recursively destructures collections on save/load.
Place before a concrete
StorageBackendin the MRO to add destructuring behavior. Lists, tuples, and dicts are broken apart so each element is stored independently; on load the original structure is reassembled.Example:
class DestructuringMemory(ValueMixin, DestructuringMixin, Memory): pass dm = DestructuringMemory(storage={}) key = dm.save([1, [2, 3]]) assert dm.load(key) == [1, [2, 3]]
- _intern_rec(value: Any, key: fleche.digest.Digest | None = None) tuple[Any, int | float][source]
Post-order traversal: recurse to leaves, decide inline-vs-store on the way back up.
Returns
(result, depth)where result is the plain value whendepth < remaining_depth(the element is inlined in its parent’sDigestedwrapper) or aDigestwhen the element was written to storage separately. Every node in the structure is visited exactly once (O(n)), unlike a separate depth-counting pass.
- put(value: Any, key: fleche.digest.Digest) fleche.digest.Digest[source]
- get(key: fleche.digest.Digest | Any) Any[source]
- class fleche.storage.base.CallStorage[source]
Bases:
KeyManagementAbstract domain interface for call storage.
- abstractmethod save(call: fleche.call.Call) fleche.digest.Digest[source]
- abstractmethod load(key: fleche.digest.Digest | str) fleche.call.Call[source]
- abstractmethod query(template: fleche.call.QueryCall) Iterable[fleche.call.Call][source]
- transform(func: Callable[[fleche.call.Call], fleche.call.Call] | None = None) None[source]
Applies a transformation function to all Call objects in the storage.
- class fleche.storage.base.CallMixin[source]
Bases:
CallStorage,StorageBackendBridges
CallStoragewithStorageBackendprimitives.Implements
save,load, andqueryusingputandget, deriving the storage key from the call’s lookup key.transformis inherited fromCallStorage.Concrete classes inherit from this and a
StorageBackendimplementation to get a fully functional call storage.- save(call: fleche.call.Call) fleche.digest.Digest[source]
- load(key: fleche.digest.Digest | str) fleche.call.Call[source]
- query(template: fleche.call.QueryCall) Iterable[fleche.call.Call][source]
Find cached calls that ‘match’ the template.
Returns all calls where the given arguments, results or metadata match exactly the stored ones. Values may be given either as they are or as
Digest.