principia_materia.io_interface.data_wrapper module
- class principia_materia.io_interface.data_wrapper.DataWrapper(title=None, prefix=None)
Bases:
BaseDataWrapper
A container for the format of a collection of data.
An object oriented wrapper to enforce input text-based data format. It’s also designed so that multiple wrappers can be added up to form a wrapper that handles all the data contained in every one of the sub-wrappers.
YAML is used as the format to read and write from file.
- Parameters:
title (str, default to None) – A comment description for the file.
prefix (str, default to None) – Prefix for the keywords when flattening the nested DataWrapper.
- dump(data, filename, allow_missing=False, overwrite=False)
Format the data into a YAML file
- Parameters:
data (dict) – The dictionary containing data to be saved.
filename (str) – The name of the file to save the data into,
allow_missing (bool, optional, default to False) – Whether to allow a declared key not to exists in the data dictionary.
overwrite (bool, optional, default to False) – When the file exists, whether to replace the content of the file with the content to be saved.
- dumps(data, allow_missing=False)
Format the data into YAML parsable string
- Parameters:
data (dict) – The dictionary containing data to be saved.
allow_missing (bool, optional, default to False) – Whether to allow a declared key not to exists in the data dictionary.
- load(filename, allow_missing=False, allow_unknown=False, load_unknown=False)
Load the data from a YAML file
- Parameters:
filename (str) – The name of the file to save the data into,
allow_missing (bool, optional, default to False) – Whether to allow a declared key not to exists in the data dictionary.
allow_unknown (bool, optional, default to False) – Whether to allow keys not declared in the container. Though even if allowed, those keys will not be loaded if load_unknown == False.
load_unknown (bool, optional, default to False) – Whether to load keys not declared in the container to be loaded in raw.
- load_dict(data, allow_missing=False, allow_unknown=False, load_unknown=False)
Load the data from a dict
- Parameters:
text (str) – A YAML string to load.
allow_missing (bool, optional, default to False) – Whether to allow a declared key not to exists in the data dictionary.
allow_unknown (bool, optional, default to False) – Whether to allow keys not declared in the container. Though even if allowed, those keys will not be loaded if load_unknown == False.
load_unknown (bool, optional, default to False) – Whether to load keys not declared in the container to be loaded in raw.
- load_generic(data, allow_missing=False, allow_unknown=False, load_unknown=False)
- loads(text, allow_missing=False, allow_unknown=False, load_unknown=False)
Load the data from a YAML string
- Parameters:
text (str) – A YAML string to load.
allow_missing (bool, optional, default to False) – Whether to allow a declared key not to exists in the data dictionary.
allow_unknown (bool, optional, default to False) – Whether to allow keys not declared in the container. Though even if allowed, those keys will not be loaded if load_unknown == False.
load_unknown (bool, optional, default to False) – Whether to load keys not declared in the container to be loaded in raw.