pymasep.common.container
Classes
Container class containing other objects. A container is not an object itself, it is more an object property. |
Module Contents
- class pymasep.common.container.Container(environment, name=None, parent=None, xml_node=None, template=None, src_copy=None)
Bases:
pymasep.common.BaseObjectContainer class containing other objects. A container is not an object itself, it is more an object property.
- Parameters:
environment – an Environment instance
name (Optional[str]) – name of the Container.
xml_node (Optional[xml.etree.ElementTree.Element]) – XML used to create the Container.
template – Template of the container. Needed if no xml_node.
parent (Optional[pymasep.common.BaseObject]) – Parent object (see objects hierarchy)
src_copy (Optional[Container]) – Container to copy. See copy_obs()
- __slots__ = ['_container']
- _container
- state()
state of the Container. ‘init’ if the object is just created or if one contained object is in ‘init’ state.
- Returns:
the state of the Container
- Return type:
str
- set_run()
Set the state of a container to run. A container must be explicitly set to run.
- add(obj)
add an object to the container.
- Parameters:
obj (pymasep.common.Object) – the object to add
- remove(obj)
remove an object from the container.
- Parameters:
obj (pymasep.common.Object) – the object to remove
- __iter__()
- __next__()
- __len__()
- __getitem__(item)
- id_str()
Create a string unique ID of the Container. Return a concatenation of the id_str of the base object and the id_str of all contained objects
- Returns:
The string unique ID
- Return type:
str
- to_xml()
Transform the Container to XML with all objects contained in the Container. See Serialization for more information.
- Returns:
XML version of the Container
- Raises:
pymasep.common.exception.ConstraintException – A container not initialized must have an initializer before streaming to XML
- Return type:
xml.etree.ElementTree.Element
- from_xml(environment, xml_node)
Transform an XML to a Container. The instance must be created before (with __init__(), passing the xml_node). See Serialization for more information.
- Parameters:
environment – The environment where the ObjectState is created.
xml_node (xml.etree.ElementTree.Element) – The XML node that contains the container information.
- Raises:
pymasep.common.exception.CreationException – A container must be empty or containing only an initialized object.
- Return type:
None
- copy_obs(params)
Deep copy the Container to a new instance.
- Parameters:
params (dict) – Not used for a Container
Note : this method copy the reference of the parent. The parent should do the parent copy and assignment