hifis_surveyval.models.mixins package¶
Submodules¶
hifis_surveyval.models.mixins.identifiable module¶
This module contains the base class for all objects that carry a unique ID.
IDs are composed of multiple parts interjected by a hierarchy separator.
- class hifis_surveyval.models.mixins.identifiable.Identifiable(object_id: str, parent_id: Optional[str] = None)[source]¶
Bases:
object
This is the abstract superclass for all objects that carry an ID.
The ID is expected to be a string (or be convertible into such and to be unique among all identifiable objects.
IDs are separated by a HIERARCHY_SEPARATOR and the part after the last separator forms the so-called “short ID”. If no hierarchical parent_id is given, the short ID and the full ID are the same.
- HIERARCHY_SEPARATOR: str = '/'¶
- __init__(object_id: str, parent_id: Optional[str] = None)[source]¶
Create a new identifiable object with a given ID.
The class will track all known IDs to prevent duplicates. A full ID is formed by merging the parent’s full ID (if it exists) and the object’s ID.
- Args:
- object_id:
A string serving as an ID to the object. It must be neither None nor empty.
- parent_id:
(Optional, Default=None) The full ID of another identifiable object that forms the hierarchical parent of this one. Used to generate the full ID.
- Raises:
- ValueError:
Signals either a duplicate or invalid object_id
- property full_id: str¶
Get the full ID of the object (includes parent_id IDs).
- Returns:
The string identifying the object with respect to any other Identifiable
- known_ids: Set[str] = {}¶
- property short_id: str¶
Get the short ID of this object (without parent_id IDs).
- Returns:
The string identifying this object with respect to its siblings
hifis_surveyval.models.mixins.yaml_constructable module¶
Provides an abstract class for classes constructed from YAML-Dictionaries.
All of these inheriting classes should define a Schema to dictate the required structure of the YAML to be parsed.
- class hifis_surveyval.models.mixins.yaml_constructable.YamlConstructable[source]¶
Bases:
abc.ABC
An abstract class for classes that can be instantiated from a YamlDict.
It defines a catchall schema that accepts everything that looks like a valid YAML mapping.
- classmethod from_yaml_dictionary(yaml: Dict[str, Union[str, List[Union[str, Dict[str, Union[str, YamlList, YamlDict]]]], Dict[str, Union[str, List[Union[str, YamlDict]], YamlDict]]]], **kwargs) → hifis_surveyval.models.mixins.yaml_constructable.YamlConstructable[source]¶
Instantiate an object of this class from a given YamlDict.
The given YAML will be validated against the schema defined for the class. If the class did not define a schema on its own (although it should) a catchall schema is provided.
- Args:
- yaml:
A dictionary as received from the YAML parser containing the data required to create a new instance of the inheriting class
- Returns:
A new instance of the overriding subclass
- schema: schema.Schema = Schema({<class 'str'>: Or(<class 'str'>, <class 'list'>, <class 'dict'>)})¶
The default schema of a YamlConstructable validates everything which is formatted like a YamlDictionary
Module contents¶
Provides mixins used in the data models.