pymasep.common.base_object

Classes

BaseObject

Base class for all functional objects for pymasep that running into an environment.

Module Contents

class pymasep.common.base_object.BaseObject(environment, name=None, parent=None, xml_node=None, template=None, src_copy=None)

Base class for all functional objects for pymasep that running into an environment. Any BaseObject can be created from template or XML. Name can be omitted if created with XML.

Parameters:
  • environment – an Environment instance

  • name (Optional[str]) – name of the BaseObject.

  • xml_node (Optional[xml.etree.ElementTree.Element]) – XML used to create the object.

  • template – Template of the base object. Needed if no xml_node or src_copy

  • parent (Optional[BaseObject]) – parent object (see objects hierarchy)

  • src_copy (Optional[BaseObject]) – The BaseObject to copy. Needed if no xml_node or template. The copy is not made into the constructor.

Raises:

pymasep.common.exception.CreationException – If no XML or no template or src_copy is present

__slots__ = ['environment', 'name', 'nature', 'parent', 'template', '_state', 'initializer']
environment
parent

parent of the base object (see objects hierarchy)

name: str | None

name of the base object

_state: str | None = None
initializer = None

initializer of the base object

template

template of the base object

nature: str | None = None

nature of the base object

property state: str

State of the BaseObject. None if the object is just created. “Init” if it misses something (input from user) to finish the creation. “Run” is the BaseObject is operational.

Returns:

The state of the BaseObject

Return type:

str

id_str()

Create a string unique ID of the BaseObject. Depends on the content of the BaseObject.

Returns:

The string unique ID

Return type:

str

get_fullname()

Return the full name of the base object including the parent name : greatparentname.parentname.name.

Returns:

The full name

Return type:

str

to_xml()

Transform the BaseObject to XML. See Serialization for more information.

Returns:

XML version of the BaseObject

Return type:

xml.etree.ElementTree.Element

from_xml(environment, xml_node)

Transform an XML to a BaseObject. The instance must be created before (with __init__(), passing the xml_node). See Serialization for more information.

Parameters:
  • environment – The environment where the BaseObject is created.

  • xml_node (xml.etree.ElementTree.Element) – The XML node containing the BaseObject data.

Return type:

None

__str__()

Transform the BaseObject to a string of its XML representation. See: ref:serialization for more information.

Returns:

A string containing the XML representation of the object.

Return type:

str

copy_obs(params)

Deep copy the BaseObject to a new instance. Template and initializer stay as the same reference as in the original.

Parameters:

params (dict) – Parameters for the copy of a BaseObject. See each Baseobject for more information.

Note : this method copy the reference of the parent. The parent should do the parent copy and assignment.