Storage#
- class Storage[source]#
storage class to save and retrieve objects.
- change_protection(key, read_protected=False, write_protected=False, silent=False)[source]#
changes the protection policy of an entry
- Parameters
key (Hashable) -- key to the entry
read_protected (bool, optional) -- read protection. Defaults to False.
write_protected (bool, optional) -- write protection. Defaults to False.
silent (bool) -- if False and and any protection changes, a warning is printed. Defaults to False.
- get_all_keys()[source]#
Fetches the keys of all the objects written to the storage so far including read protected ones.
- Returns
Iterable[str] -- an iterable of the keys to the
- get_keys()[source]#
Fetches the keys of the objects written to the storage so far.
Note
to get keys of all entries included read protected ones call
get_all_keys
instead.- Returns
Iterable[str] -- an iterable of the keys to the
- get_protection_status(key)[source]#
fetches the protection status of an entry.
- Parameters
key (Hashable) -- key to the entry
- Returns
Tuple[bool, bool] -- read and write protection status respectively.
- read(key, silent=False)[source]#
read from the storage.
- Parameters
key (Hashable) -- key to fetch the desired object.
silent (bool) -- if False and entry is read protected, a warning is printed. Defaults to False.
- Returns
Any -- the desired object. If key does not exist, None is returned.
- remove(key, silent=False)[source]#
removes an entry from the storage.
- Parameters
key (Hashable) -- key to the entry.
silent (bool, optional) -- if False and entry is write protected a warning is printed. Defaults to False.
- write(key, obj, read_protected=False, write_protected=False, silent=False)[source]#
writes to the storage.
- Parameters
key (Hashable) -- key to access the object in future retrievals
obj (Any) -- object to store
read_protected (bool) -- prints warning if in future key accessed by a read call. Defaults to False.
write_protected (bool) -- print warning if in future key accessed by a write call. Defaults to False.
silent (bool) -- if False and entry is write protected, a warning is printed. Defaults to False.