viat.protocols
¶
Protocols upon which viat is built.
ViatAttributeMutator
¶
Bases: MutableMapping[str, JsonT]
A scoped attribute mutator for a storage entry.
This is not a protocol because it inherits the MutableMapping ABC.
ViatAttributeReader
¶
A scoped attribute reader for a storage entry.
This is not a protocol because it inherits the Mapping ABC.
ViatAttributeStorage
¶
Bases: AbstractContextManager[ViatAttributeStorageConnection], Protocol
A storage for virtual attributes.
It is only meant to be used indirectly as a context manager that emits a
[ViatAttributeStorageConnection][..ViatAttributeStorageConnection].
Upon exiting the context manager, the updates should be committed.
Example
The following code updates an attribute and saves the result:
with vault.storage as conn, conn.get_mutator(path) as mut:
mut['key'] = 'value'
Once the inner context exits, the connection validates the update. Once the outer context manager exits, the storage saves all updates that were made.
Source code in src/viat/protocols.py
ViatAttributeStorageConnection
¶
Bases: Protocol
An abstraction for managing storage mutators.
Connection providers may use anything from a simple dictionary to an open database connection.
Example
The following code updates an attribute:
with conn.get_mutator(path) as mut:
mut['key'] = 'value'
Once the context manager exits, the connection validates the update.
Source code in src/viat/protocols.py
get_mutator(path)
¶
Create a context manager that produces an attribute mutator.
Upon exiting, the context manager must validate the state of the mutator.
Parameters:
Returns:
-
AbstractContextManager[ViatAttributeMutator]–A context manager wrapping a mutator.
Source code in src/viat/protocols.py
get_reader(path)
¶
Create a context manager that produces an attribute reader.
Parameters:
Returns:
-
AbstractContextManager[ViatAttributeReader]–A context manager wrapping a reader.
Source code in src/viat/protocols.py
iter_known_paths()
¶
Iterate all paths with at least one attribute set.
Returns:
ViatFileTracker
¶
Bases: Protocol
An abstraction for enumerating and emitting paths.
It can be a directory walker, a static file list or anything else.
Source code in src/viat/protocols.py
is_tracked(path)
¶
iter_paths()
¶
validate_tracked(path)
¶
Validate that a file is being tracked and emit and otherwise emit
ViatUntrackedFileWarning.
Parameters:
-
path(Path) –The file path.