Implementation of storage Storage.
Implements application’s persistent storage interface IStorage. The implementation is provided by FileStorage class. It should be constructed by some infrastructure component and distributed to other components. Individual components should not instantiate it directly.
FileStorage class.
Bases: builtins.object
Application’s persistent storage.
Provides access to application’s persistent storage. Any arbitrary variables can be saved to it. Data are stored in text files.
This storage implementation utilizes local filesystem, specifically a subdirectory of user configuration directory named storage. Data are stored in text files. The directory is automatically created if it does not exists. Storage content is read upon construction and cached into memory. This class does not provide any means to re-read the storage content from disk.
Note
This class can be instantiated only once.
Parameters: | configuration (IConfiguration) – Application configuration. |
---|
Returns IStoragePortion instance set to section and realm.
Note
If section or realm does not exists the implementation should not create either of them right away but rather on first value save.
Parameters: |
|
---|---|
Returns: | IStoragePortion instance |
Return type: | IStoragePortion |
Returns all realms that exists in the storage.
Returns: | Iterable of realm names. |
---|---|
Return type: | Iterable<str> |
Returns a cached value from the persistent storage.
Parameters: |
|
---|---|
Returns: | Value of the passed variable. |
Return type: | str |
Raises KeyError: | |
If variable, section or realm does not exists. |
Returns True if the storage contains variable.
Parameters: |
|
---|---|
Returns: | True if variable is present in the storage. |
Return type: | bool |
Deletes the realm including all information that contains from the persistent storage.
Parameters: | realm (str) – Name of a separate storage entity (typically represented by a file). |
---|---|
Raises: |
|
Saves a value to the persistent storage.
A value passed as value parameter will be saved to the persistent storage under the name passed as variable argument.
Note
A string representation of the value is saved (str(value)).
Parameters: |
|
---|
Removes variable from the persistent storage.
If variable existed to be removed, returns True; otherwise return False.
Parameters: |
|
---|---|
Returns: | True if variable existed; False otherwise. |
Return type: | bool |
Raises KeyError: | |
If section or realm does not exists. |
_StoragePortion class.
Bases: builtins.object
Provides access to a part of the persistent storage.
Portion of a storage (which can be any FileStorage-like class) that can be accessed is defined by realm and section. While the section can be changed dynamically, realm can not be changed for entire lifetime of the _StoragePortion-type object.
See also: FileStorage.
Parameters: |
|
---|
Returns a cached value from the persistent storage.
Parameters: |
|
---|---|
Returns: | Value of the passed variable. |
Return type: | str |
Raises KeyError: | |
If variable or section does not exists. |
Returns true if the storage contains variable.
Parameters: |
|
---|---|
Returns: | true if variable is present in the storage. |
Return type: | bool |
Saves a value to the persistent storage.
A value passed as value parameter will be saved to a persistent storage under the name passed as variable argument.
Note
A string representation of the value is saved (str(value)).
Parameters: |
|
---|
Removes variable from the persistent storage.
If variable existed to be removed, returns True; otherwise return False.
Parameters: |
|
---|---|
Returns: | True if variable existed; False otherwise. |
Return type: | bool |
Raises KeyError: | |
If section does not exists. |