principia_materia.io_interface.base_data_wrapper module
- class principia_materia.io_interface.base_data_wrapper.BaseDataWrapper(title=None)
- Bases: - ABC- A container stores how to process the dumping/loading of a collection of data - An object oriented wrapper to load and dump data in a certain format. - It’s also designed multiple wrappers can be added up to form a wrapper that handles all the data contained in every one of the sub-wrappers. - Parameters:
- title (str, default to None) – A comment description for the file. 
 - add_item(key, choices=None, dtype=None, load_dtype=None, save_dtype=None, optional=False, help=None, alias=None, depends=None)
- Add an item of data to the container. - Parameters:
- key (str) – The name of the item to be save in the data file. 
- dtype (str, default to None) – Data type of the item. The corresponding save/load functions will be used to save/load the item. 
- load_dtype (str or callable, default to None) – The function to load the item. 
- save_dtype (str or callable, default to None) – The function to save the item. 
- optional (bool, default to False) – Whether the item is optional. 
- help (str, default to None) – The description of the item. 
- alias (list of str, default to None) – A list aliases of the item keyword. 
- depends (list of str, default to None) – The keywords that are required when the item is present. 
 
 
 - copy()
 - delete_item(key, allow_missing=False)
- Delete an item of the data from the container. 
 - abstract dump(data, filename, allow_missing=False, overwrite=False)
- Dump the data into a data 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)
- Dump the data into 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. 
 
 
 - get_alias_map()
 - get_all_names_aliases()
 - abstract load(filename, allow_missing=False, allow_unknown=False, load_unknown=False)
- Load the data from a data 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. 
 
 
 - loads(text, allow_missing=False, allow_unknown=False, load_unknown=False)
- Load the data from a string - Parameters:
- text (str) – Data in text format, 
- 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. 
 
 
 - register_dtype(name, load_dtype, save_dtype)
- Add an load and save dtype to the container - Parameters:
- name (str) – The name of the dtype. 
- load_dtype (callable) – A callable to perform the load dtype. It’ll process the data and return its final form after loaded from data file. 
- save_dtype (callable) – A callable to perform the save dtype. It’ll process the data and return the value to be dumped to the data file. 
 
 
 - self_check(try_fix=True)
 - verify_data(data)