capellambse.model.common package¶
Common classes used by all MelodyModel functions.
- capellambse.model.common.XTYPE_ANCHORS = {'capellambse.extensions.filtering': 'filtering', 'capellambse.extensions.reqif._capellareq': 'CapellaRequirements', 'capellambse.extensions.reqif._requirements': 'Requirements', 'capellambse.model': 'org.polarsys.capella.core.data.capellamodeller', 'capellambse.model.crosslayer': 'org.polarsys.capella.core.data', 'capellambse.model.diagram': 'viewpoint', 'capellambse.model.layers': 'org.polarsys.capella.core.data'}¶
A mapping from anchor modules to Capella packages.
This dictionary maps Python modules and packages to the Capella packages they represent.
build_xtype
and related functions/classes can then use this information to automatically derive anxsi:type
from any class that is defined in such an anchor module (or a submodule of one).
- capellambse.model.common.XTYPE_HANDLERS: dict[str | None, dict[str, type[Any]]] = {'org.polarsys.capella.core.data.ctx:SystemAnalysis': {'org.polarsys.capella.core.data.ctx:Capability': <class 'capellambse.model.layers.ctx.Capability'>, 'org.polarsys.capella.core.data.ctx:CapabilityExploitation': <class 'capellambse.model.layers.ctx.CapabilityExploitation'>, 'org.polarsys.capella.core.data.ctx:CapabilityInvolvement': <class 'capellambse.model.layers.ctx.CapabilityInvolvement'>, 'org.polarsys.capella.core.data.ctx:CapabilityPkg': <class 'capellambse.model.layers.ctx.CapabilityPkg'>, 'org.polarsys.capella.core.data.ctx:Mission': <class 'capellambse.model.layers.ctx.Mission'>, 'org.polarsys.capella.core.data.ctx:MissionInvolvement': <class 'capellambse.model.layers.ctx.MissionInvolvement'>, 'org.polarsys.capella.core.data.ctx:MissionPkg': <class 'capellambse.model.layers.ctx.MissionPkg'>, 'org.polarsys.capella.core.data.ctx:SystemComponent': <class 'capellambse.model.layers.ctx.SystemComponent'>, 'org.polarsys.capella.core.data.ctx:SystemComponentPkg': <class 'capellambse.model.layers.ctx.SystemComponentPkg'>, 'org.polarsys.capella.core.data.ctx:SystemFunction': <class 'capellambse.model.layers.ctx.SystemFunction'>, 'org.polarsys.capella.core.data.ctx:SystemFunctionPkg': <class 'capellambse.model.layers.ctx.SystemFunctionPkg'>}, 'org.polarsys.capella.core.data.la:LogicalArchitecture': {'org.polarsys.capella.core.data.la:CapabilityRealization': <class 'capellambse.model.layers.la.CapabilityRealization'>, 'org.polarsys.capella.core.data.la:CapabilityRealizationPkg': <class 'capellambse.model.layers.la.CapabilityRealizationPkg'>, 'org.polarsys.capella.core.data.la:LogicalComponent': <class 'capellambse.model.layers.la.LogicalComponent'>, 'org.polarsys.capella.core.data.la:LogicalComponentPkg': <class 'capellambse.model.layers.la.LogicalComponentPkg'>, 'org.polarsys.capella.core.data.la:LogicalFunction': <class 'capellambse.model.layers.la.LogicalFunction'>, 'org.polarsys.capella.core.data.la:LogicalFunctionPkg': <class 'capellambse.model.layers.la.LogicalFunctionPkg'>}, 'org.polarsys.capella.core.data.oa:OperationalAnalysis': {'org.polarsys.capella.core.data.oa:CommunicationMean': <class 'capellambse.model.layers.oa.CommunicationMean'>, 'org.polarsys.capella.core.data.oa:Entity': <class 'capellambse.model.layers.oa.Entity'>, 'org.polarsys.capella.core.data.oa:EntityOperationalCapabilityInvolvement': <class 'capellambse.model.layers.oa.EntityOperationalCapabilityInvolvement'>, 'org.polarsys.capella.core.data.oa:EntityPkg': <class 'capellambse.model.layers.oa.EntityPkg'>, 'org.polarsys.capella.core.data.oa:OperationalActivity': <class 'capellambse.model.layers.oa.OperationalActivity'>, 'org.polarsys.capella.core.data.oa:OperationalActivityPkg': <class 'capellambse.model.layers.oa.OperationalActivityPkg'>, 'org.polarsys.capella.core.data.oa:OperationalCapability': <class 'capellambse.model.layers.oa.OperationalCapability'>, 'org.polarsys.capella.core.data.oa:OperationalCapabilityPkg': <class 'capellambse.model.layers.oa.OperationalCapabilityPkg'>, 'org.polarsys.capella.core.data.oa:OperationalProcess': <class 'capellambse.model.layers.oa.OperationalProcess'>}, 'org.polarsys.capella.core.data.pa:PhysicalArchitecture': {'org.polarsys.capella.core.data.pa:PhysicalComponent': <class 'capellambse.model.layers.pa.PhysicalComponent'>, 'org.polarsys.capella.core.data.pa:PhysicalComponentPkg': <class 'capellambse.model.layers.pa.PhysicalComponentPkg'>, 'org.polarsys.capella.core.data.pa:PhysicalFunction': <class 'capellambse.model.layers.pa.PhysicalFunction'>, 'org.polarsys.capella.core.data.pa:PhysicalFunctionPkg': <class 'capellambse.model.layers.pa.PhysicalFunctionPkg'>}, None: {'CapellaRequirements:CapellaIncomingRelation': <class 'capellambse.extensions.reqif._capellareq.CapellaIncomingRelation'>, 'CapellaRequirements:CapellaModule': <class 'capellambse.extensions.reqif._capellareq.CapellaModule'>, 'CapellaRequirements:CapellaOutgoingRelation': <class 'capellambse.extensions.reqif._capellareq.CapellaOutgoingRelation'>, 'CapellaRequirements:CapellaTypesFolder': <class 'capellambse.extensions.reqif._capellareq.CapellaTypesFolder'>, 'Requirements:AttributeDefinition': <class 'capellambse.extensions.reqif._requirements.AttributeDefinition'>, 'Requirements:AttributeDefinitionEnumeration': <class 'capellambse.extensions.reqif._requirements.AttributeDefinitionEnumeration'>, 'Requirements:BooleanValueAttribute': <class 'capellambse.extensions.reqif._requirements.BooleanValueAttribute'>, 'Requirements:DataTypeDefinition': <class 'capellambse.extensions.reqif._requirements.DataTypeDefinition'>, 'Requirements:DateValueAttribute': <class 'capellambse.extensions.reqif._requirements.DateValueAttribute'>, 'Requirements:EnumValue': <class 'capellambse.extensions.reqif._requirements.EnumValue'>, 'Requirements:EnumerationDataTypeDefinition': <class 'capellambse.extensions.reqif._requirements.EnumerationDataTypeDefinition'>, 'Requirements:EnumerationValueAttribute': <class 'capellambse.extensions.reqif._requirements.EnumerationValueAttribute'>, 'Requirements:Folder': <class 'capellambse.extensions.reqif._requirements.Folder'>, 'Requirements:IntegerValueAttribute': <class 'capellambse.extensions.reqif._requirements.IntegerValueAttribute'>, 'Requirements:InternalRelation': <class 'capellambse.extensions.reqif._requirements.InternalRelation'>, 'Requirements:ModuleType': <class 'capellambse.extensions.reqif._requirements.ModuleType'>, 'Requirements:RealValueAttribute': <class 'capellambse.extensions.reqif._requirements.RealValueAttribute'>, 'Requirements:RelationType': <class 'capellambse.extensions.reqif._requirements.RelationType'>, 'Requirements:Requirement': <class 'capellambse.extensions.reqif._requirements.Requirement'>, 'Requirements:RequirementType': <class 'capellambse.extensions.reqif._requirements.RequirementType'>, 'Requirements:StringValueAttribute': <class 'capellambse.extensions.reqif._requirements.StringValueAttribute'>, 'diagram:DSemanticDiagram': <class 'capellambse.model.diagram.Diagram'>, 'filtering:ComposedFilteringResult': <class 'capellambse.extensions.filtering.ComposedFilteringResult'>, 'filtering:FilteringCriterion': <class 'capellambse.extensions.filtering.FilteringCriterion'>, 'filtering:FilteringCriterionPkg': <class 'capellambse.extensions.filtering.FilteringCriterionPkg'>, 'filtering:FilteringModel': <class 'capellambse.extensions.filtering.FilteringModel'>, 'filtering:FilteringResult': <class 'capellambse.extensions.filtering.FilteringResult'>, 'org.polarsys.capella.core.data.capellacommon:DeepHistoryPseudoState': <class 'capellambse.model.crosslayer.capellacommon.DeepHistoryPseudoState'>, 'org.polarsys.capella.core.data.capellacommon:FinalState': <class 'capellambse.model.crosslayer.capellacommon.FinalState'>, 'org.polarsys.capella.core.data.capellacommon:ForkPseudoState': <class 'capellambse.model.crosslayer.capellacommon.ForkPseudoState'>, 'org.polarsys.capella.core.data.capellacommon:GenericTrace': <class 'capellambse.model.crosslayer.capellacommon.GenericTrace'>, 'org.polarsys.capella.core.data.capellacommon:InitialPseudoState': <class 'capellambse.model.crosslayer.capellacommon.InitialPseudoState'>, 'org.polarsys.capella.core.data.capellacommon:JoinPseudoState': <class 'capellambse.model.crosslayer.capellacommon.JoinPseudoState'>, 'org.polarsys.capella.core.data.capellacommon:Mode': <class 'capellambse.model.crosslayer.capellacommon.Mode'>, 'org.polarsys.capella.core.data.capellacommon:Region': <class 'capellambse.model.crosslayer.capellacommon.Region'>, 'org.polarsys.capella.core.data.capellacommon:ShallowHistoryPseudoState': <class 'capellambse.model.crosslayer.capellacommon.ShallowHistoryPseudoState'>, 'org.polarsys.capella.core.data.capellacommon:State': <class 'capellambse.model.crosslayer.capellacommon.State'>, 'org.polarsys.capella.core.data.capellacommon:StateMachine': <class 'capellambse.model.crosslayer.capellacommon.StateMachine'>, 'org.polarsys.capella.core.data.capellacommon:StateTransition': <class 'capellambse.model.crosslayer.capellacommon.StateTransition'>, 'org.polarsys.capella.core.data.capellacommon:TerminatePseudoState': <class 'capellambse.model.crosslayer.capellacommon.TerminatePseudoState'>, 'org.polarsys.capella.core.data.capellacore:BooleanPropertyValue': <class 'capellambse.model.crosslayer.capellacore.BooleanPropertyValue'>, 'org.polarsys.capella.core.data.capellacore:Constraint': <class 'capellambse.model.crosslayer.capellacore.Constraint'>, 'org.polarsys.capella.core.data.capellacore:EnumerationPropertyLiteral': <class 'capellambse.model.crosslayer.capellacore.EnumerationPropertyLiteral'>, 'org.polarsys.capella.core.data.capellacore:EnumerationPropertyType': <class 'capellambse.model.crosslayer.capellacore.EnumerationPropertyType'>, 'org.polarsys.capella.core.data.capellacore:EnumerationPropertyValue': <class 'capellambse.model.crosslayer.capellacore.EnumerationPropertyValue'>, 'org.polarsys.capella.core.data.capellacore:FloatPropertyValue': <class 'capellambse.model.crosslayer.capellacore.FloatPropertyValue'>, 'org.polarsys.capella.core.data.capellacore:Generalization': <class 'capellambse.model.crosslayer.capellacore.Generalization'>, 'org.polarsys.capella.core.data.capellacore:IntegerPropertyValue': <class 'capellambse.model.crosslayer.capellacore.IntegerPropertyValue'>, 'org.polarsys.capella.core.data.capellacore:PropertyValueGroup': <class 'capellambse.model.crosslayer.capellacore.PropertyValueGroup'>, 'org.polarsys.capella.core.data.capellacore:PropertyValuePkg': <class 'capellambse.model.crosslayer.capellacore.PropertyValuePkg'>, 'org.polarsys.capella.core.data.capellacore:StringPropertyValue': <class 'capellambse.model.crosslayer.capellacore.StringPropertyValue'>, 'org.polarsys.capella.core.data.capellamodeller:Library': <class 'capellambse.model.MelodyModel'>, 'org.polarsys.capella.core.data.capellamodeller:Project': <class 'capellambse.model.MelodyModel'>, 'org.polarsys.capella.core.data.cs:ComponentRealization': <class 'capellambse.model.crosslayer.cs.ComponentRealization'>, 'org.polarsys.capella.core.data.cs:ExchangeItemAllocation': <class 'capellambse.model.crosslayer.cs.ExchangeItemAllocation'>, 'org.polarsys.capella.core.data.cs:Interface': <class 'capellambse.model.crosslayer.cs.Interface'>, 'org.polarsys.capella.core.data.cs:InterfacePkg': <class 'capellambse.model.crosslayer.cs.InterfacePkg'>, 'org.polarsys.capella.core.data.cs:Part': <class 'capellambse.model.crosslayer.cs.Part'>, 'org.polarsys.capella.core.data.cs:PhysicalLink': <class 'capellambse.model.crosslayer.cs.PhysicalLink'>, 'org.polarsys.capella.core.data.cs:PhysicalPath': <class 'capellambse.model.crosslayer.cs.PhysicalPath'>, 'org.polarsys.capella.core.data.cs:PhysicalPort': <class 'capellambse.model.crosslayer.cs.PhysicalPort'>, 'org.polarsys.capella.core.data.ctx:SystemAnalysis': <class 'capellambse.model.layers.ctx.SystemAnalysis'>, 'org.polarsys.capella.core.data.fa:AbstractFunction': <class 'capellambse.model.crosslayer.fa.AbstractFunction'>, 'org.polarsys.capella.core.data.fa:ComponentExchange': <class 'capellambse.model.crosslayer.fa.ComponentExchange'>, 'org.polarsys.capella.core.data.fa:ComponentPort': <class 'capellambse.model.crosslayer.fa.ComponentPort'>, 'org.polarsys.capella.core.data.fa:ControlNode': <class 'capellambse.model.crosslayer.fa.ControlNode'>, 'org.polarsys.capella.core.data.fa:FunctionInputPort': <class 'capellambse.model.crosslayer.fa.FunctionInputPort'>, 'org.polarsys.capella.core.data.fa:FunctionOutputPort': <class 'capellambse.model.crosslayer.fa.FunctionOutputPort'>, 'org.polarsys.capella.core.data.fa:FunctionPort': <class 'capellambse.model.crosslayer.fa.FunctionPort'>, 'org.polarsys.capella.core.data.fa:FunctionRealization': <class 'capellambse.model.crosslayer.fa.FunctionRealization'>, 'org.polarsys.capella.core.data.fa:FunctionalChain': <class 'capellambse.model.crosslayer.fa.FunctionalChain'>, 'org.polarsys.capella.core.data.fa:FunctionalChainInvolvementFunction': <class 'capellambse.model.crosslayer.fa.FunctionalChainInvolvementFunction'>, 'org.polarsys.capella.core.data.fa:FunctionalChainInvolvementLink': <class 'capellambse.model.crosslayer.fa.FunctionalChainInvolvementLink'>, 'org.polarsys.capella.core.data.fa:FunctionalChainReference': <class 'capellambse.model.crosslayer.fa.FunctionalChainReference'>, 'org.polarsys.capella.core.data.fa:FunctionalExchange': <class 'capellambse.model.crosslayer.fa.FunctionalExchange'>, 'org.polarsys.capella.core.data.information.datatype:BooleanType': <class 'capellambse.model.crosslayer.information.datatype.BooleanType'>, 'org.polarsys.capella.core.data.information.datatype:Enumeration': <class 'capellambse.model.crosslayer.information.datatype.Enumeration'>, 'org.polarsys.capella.core.data.information.datatype:NumericType': <class 'capellambse.model.crosslayer.information.datatype.NumericType'>, 'org.polarsys.capella.core.data.information.datatype:PhysicalQuantity': <class 'capellambse.model.crosslayer.information.datatype.PhysicalQuantity'>, 'org.polarsys.capella.core.data.information.datatype:StringType': <class 'capellambse.model.crosslayer.information.datatype.StringType'>, 'org.polarsys.capella.core.data.information.datavalue:ComplexValue': <class 'capellambse.model.crosslayer.information.datavalue.ComplexValue'>, 'org.polarsys.capella.core.data.information.datavalue:EnumerationLiteral': <class 'capellambse.model.crosslayer.information.datavalue.EnumerationLiteral'>, 'org.polarsys.capella.core.data.information.datavalue:EnumerationReference': <class 'capellambse.model.crosslayer.information.datavalue.EnumerationReference'>, 'org.polarsys.capella.core.data.information.datavalue:LiteralNumericValue': <class 'capellambse.model.crosslayer.information.datavalue.LiteralNumericValue'>, 'org.polarsys.capella.core.data.information.datavalue:LiteralStringValue': <class 'capellambse.model.crosslayer.information.datavalue.LiteralStringValue'>, 'org.polarsys.capella.core.data.information.datavalue:ValuePart': <class 'capellambse.model.crosslayer.information.datavalue.ValuePart'>, 'org.polarsys.capella.core.data.information:Association': <class 'capellambse.model.crosslayer.information.Association'>, 'org.polarsys.capella.core.data.information:Class': <class 'capellambse.model.crosslayer.information.Class'>, 'org.polarsys.capella.core.data.information:Collection': <class 'capellambse.model.crosslayer.information.Collection'>, 'org.polarsys.capella.core.data.information:DataPkg': <class 'capellambse.model.crosslayer.information.DataPkg'>, 'org.polarsys.capella.core.data.information:ExchangeItem': <class 'capellambse.model.crosslayer.information.ExchangeItem'>, 'org.polarsys.capella.core.data.information:ExchangeItemElement': <class 'capellambse.model.crosslayer.information.ExchangeItemElement'>, 'org.polarsys.capella.core.data.information:InformationRealization': <class 'capellambse.model.crosslayer.information.InformationRealization'>, 'org.polarsys.capella.core.data.information:PortAllocation': <class 'capellambse.model.crosslayer.information.PortAllocation'>, 'org.polarsys.capella.core.data.information:Property': <class 'capellambse.model.crosslayer.information.Property'>, 'org.polarsys.capella.core.data.information:Union': <class 'capellambse.model.crosslayer.information.Union'>, 'org.polarsys.capella.core.data.information:Unit': <class 'capellambse.model.crosslayer.information.Unit'>, 'org.polarsys.capella.core.data.interaction:AbstractCapabilityExtend': <class 'capellambse.model.crosslayer.interaction.AbstractCapabilityExtend'>, 'org.polarsys.capella.core.data.interaction:AbstractCapabilityGeneralization': <class 'capellambse.model.crosslayer.interaction.AbstractCapabilityGeneralization'>, 'org.polarsys.capella.core.data.interaction:AbstractCapabilityInclude': <class 'capellambse.model.crosslayer.interaction.AbstractCapabilityInclude'>, 'org.polarsys.capella.core.data.interaction:AbstractFunctionAbstractCapabilityInvolvement': <class 'capellambse.model.crosslayer.interaction.AbstractFunctionAbstractCapabilityInvolvement'>, 'org.polarsys.capella.core.data.interaction:CombinedFragment': <class 'capellambse.model.crosslayer.interaction.CombinedFragment'>, 'org.polarsys.capella.core.data.interaction:EventReceiptOperation': <class 'capellambse.model.crosslayer.interaction.EventReceiptOperation'>, 'org.polarsys.capella.core.data.interaction:EventSentOperation': <class 'capellambse.model.crosslayer.interaction.EventSentOperation'>, 'org.polarsys.capella.core.data.interaction:Execution': <class 'capellambse.model.crosslayer.interaction.Execution'>, 'org.polarsys.capella.core.data.interaction:ExecutionEnd': <class 'capellambse.model.crosslayer.interaction.ExecutionEnd'>, 'org.polarsys.capella.core.data.interaction:ExecutionEvent': <class 'capellambse.model.crosslayer.interaction.ExecutionEvent'>, 'org.polarsys.capella.core.data.interaction:FragmentEnd': <class 'capellambse.model.crosslayer.interaction.FragmentEnd'>, 'org.polarsys.capella.core.data.interaction:InstanceRole': <class 'capellambse.model.crosslayer.interaction.InstanceRole'>, 'org.polarsys.capella.core.data.interaction:InteractionOperand': <class 'capellambse.model.crosslayer.interaction.InteractionOperand'>, 'org.polarsys.capella.core.data.interaction:InteractionState': <class 'capellambse.model.crosslayer.interaction.InteractionState'>, 'org.polarsys.capella.core.data.interaction:MessageEnd': <class 'capellambse.model.crosslayer.interaction.MessageEnd'>, 'org.polarsys.capella.core.data.interaction:Scenario': <class 'capellambse.model.crosslayer.interaction.Scenario'>, 'org.polarsys.capella.core.data.interaction:SequenceMessage': <class 'capellambse.model.crosslayer.interaction.SequenceMessage'>, 'org.polarsys.capella.core.data.interaction:StateFragment': <class 'capellambse.model.crosslayer.interaction.StateFragment'>, 'org.polarsys.capella.core.data.la:LogicalArchitecture': <class 'capellambse.model.layers.la.LogicalArchitecture'>, 'org.polarsys.capella.core.data.oa:OperationalAnalysis': <class 'capellambse.model.layers.oa.OperationalAnalysis'>, 'org.polarsys.capella.core.data.pa:PhysicalArchitecture': <class 'capellambse.model.layers.pa.PhysicalArchitecture'>, 'sequence:SequenceDDiagram': <class 'capellambse.model.diagram.Diagram'>, 'viewpoint:DRepresentationDescriptor': <class 'capellambse.model.diagram.Diagram'>}}¶
Defines a mapping between
xsi:type
s and wrapper classes.The first layer’s keys can be either
None
or thexsi:type
of the architectural layer that the wrapper should be applied to. In the case ofNone
, the wrapper will be applied to all layers. Note that layer-specific wrappers have precedence over layer-agnostic ones.These keys map to a further dictionary. This second layer maps from the
xsi:type
(s) that each wrapper handles to the wrapper class.
- capellambse.model.common.build_xtype(class_)¶
- Parameters:
class_ (type[ModelObject])
- Return type:
- capellambse.model.common.enumliteral(generic_element, attr, default='NOT_SET')¶
- Parameters:
generic_element (GenericElement)
attr (str)
default (str)
- Return type:
- capellambse.model.common.find_wrapper(typehint)¶
Find the possible wrapper classes for the hinted type.
The typehint is either a single class name, or a namespace prefix and class name separated by
:
. This function searches for all known wrapper classes that match the given namespace prefix (if any) and which have the given name, and returns them as a tuple. If no matching wrapper classes are found, an empty tuple is returned.- Parameters:
typehint (str)
- Return type:
tuple[type[ModelObject], …]
- capellambse.model.common.set_accessor(cls, attr, accessor)¶
- Parameters:
cls (type[ModelObject])
attr (str)
accessor (Accessor)
- Return type:
None
- capellambse.model.common.set_self_references(*args)¶
- Parameters:
args (tuple[type[ModelObject], str])
- Return type:
None
- capellambse.model.common.xtype_handler(arch=None, /, *xtypes)¶
Register a class as handler for a specific
xsi:type
.arch
is thexsi:type
of the desired architecture. It must always be a simple string or None. In the latter case the definition applies to all elements regardless of their architectural layer. Architecture-specific definitions will always win over architecture-independent ones.Each string given in
xtypes
notes anxsi:type
of elements that this class handles. It is possible to specify multiple values, in which case the class will be registered for eachxsi:type
under the architectural layer given inarch
.Handler classes’
__init__
methods must accept two positional arguments. The first argument is theMelodyModel
instance which loaded the corresponding model, and the second one is the LXML element that needs to be handled.Example:
>>> @xtype_handler('arch:xtype', 'xtype:1', 'xtype:2') ... class Test: ... _xmltag = "ownedTests" ... def from_model(self, model, element, /): ... ... # Instantiate from model XML element
Submodules¶
capellambse.model.common.accessors module¶
- class capellambse.model.common.accessors.Accessor¶
Bases:
Generic
[T
]Super class for all Accessor types.
- __init__()¶
- Return type:
None
- class capellambse.model.common.accessors.AlternateAccessor¶
Bases:
Accessor
[T
]Provides access to an “alternate” form of the object.
- class_¶
- class capellambse.model.common.accessors.AttrProxyAccessor¶
Bases:
WritableAccessor
[T
],PhysicalAccessor
[T
]Provides access to elements that are linked in an attribute.
- __init__(class_, attr, *, aslist=None, list_extra_args=None)¶
Create an AttrProxyAccessor.
- Parameters:
class – The proxy class. Currently only used for type hints.
attr (str) – The XML attribute to handle.
aslist (type[ElementList] | None) – If None, the attribute contains at most one element reference, and either None or the constructed proxy will be returned. If not None, must be a subclass of
ElementList
. It will be used to return a list of all matched objects.list_extra_args (Mapping[str, Any] | None) – Extra arguments to pass to the
ElementList
constructor.class_ (type[T] | None)
- attr¶
- delete(elmlist, obj)¶
Delete the
obj
from the model.- Parameters:
elmlist (ElementListCouplingMixin)
obj (ModelObject)
- Return type:
None
- insert(elmlist, index, value)¶
Insert the
value
object into the model.The object must be inserted at an appropriate place, so that, if
elmlist
were to be created afresh,value
would show up at indexindex
.- Parameters:
elmlist (ElementListCouplingMixin)
index (int)
value (ModelObject | _NewObject)
- Return type:
None
- purge_references(obj, target)¶
Purge references to the given object from the model.
This method is called while deleting physical objects, in order to get rid of references to that object (and its descendants). Reference purging is done in two steps, which is why this method returns a context manager.
The first step, executed by the
__enter__
method, collects references to the target and ensures that deleting them would result in a valid model. If any validity constraints would be violated, an exception is raised to indicate as such, and the whole operation is aborted. This is also when the relevant “capellambse.delete” audit events are fired for each reference.Once all
__enter__
methods have been called, the target object is deleted from the model. Then all__exit__
methods are called, which triggers the actual deletion of all previously discovered references.As per the context manager protocol,
__exit__
will always be called after__enter__
, even if the operation is to be aborted. The__exit__
method must therefore inspect whether an exception was passed in or not in order to know whether the operation succeeded.In order to not confuse other context managers and keep the model consistent,
__exit__
must not raise any further exceptions. Exceptions should instead be logged to stderr, for example by using thelogging.Logger.exception()
facility.The
purge_references
method will only be called for Accessor instances that actually contain a reference.- Parameters:
obj (ModelObject) – The model object to purge references from.
target (ModelObject) – The object that is to be deleted; references to this object will be purged.
- Returns:
A context manager that deals with purging references in a transactional manner.
- Return type:
- Raises:
InvalidModificationError – Raised by the returned context manager’s
__enter__
method if the attempted modification would result in an invalid model. Note that it is generally preferred to allow the operation and take the necessary steps to keep the model consistent, if possible. This can be achieved for example by deleting dependent objects along with the original deletion target.Exception – Any exception may be raised before
__enter__
returns in order to abort the transaction and prevent theobj
from being deleted. No exceptions must be raised by__exit__
.
Examples
A simple implementation for purging a single object reference could look like this:
@contextlib.contextmanager def purge_references(self, obj, target): assert self.__get__(obj, type(obj)) == target sys.audit("capellambse.delete", obj, self.__name__, None) yield try: self.__delete__(obj) except Exception: LOGGER.exception("Could not purge a dangling reference")
- class capellambse.model.common.accessors.AttributeMatcherAccessor¶
Bases:
DirectProxyAccessor
[T
]- __init__(class_, xtypes=None, *, aslist=None, attributes, **kwargs)¶
Create a DirectProxyAccessor.
- Parameters:
class – The proxy class.
xtypes (str | type[T] | Iterable[str | type[T]] | None) – The
xsi:type
(s) of the child element(s). If None, then the constructed proxy will be passed the original element instead of a child.aslist (type[ElementList] | None) – If None, only a single element must match, which will be returned directly. If not None, must be a subclass of
ElementList
, which will be used to return a list of all matched objects.follow_abstract – Follow the link in the
abstractType
XML attribute of each list member and instantiate that object instead. The default is to instantiate the child elements directly.list_extra_args – Extra arguments to pass to the
ElementList
constructor.rootelem – A class or
xsi:type
(or list thereof) that defines the path from the current object’s XML element to the search root. If None, the current element will be used directly.single_attr – If objects can be created with only a single attribute specified, this argument is the name of that attribute. This
create_singleattr()
.class_ (type[T])
- Return type:
None
- attributes¶
- class capellambse.model.common.accessors.CustomAccessor¶
Bases:
PhysicalAccessor
[T
]Customizable alternative to the DirectProxyAccessor.
Deprecated since version 0.5.4: Deprecated due to overcomplexity and (ironically) a lack of flexibility.
- __init__(class_, *elmfinders, elmmatcher=<built-in function contains>, matchtransform=<function CustomAccessor.<lambda>>, aslist=None)¶
Create a CustomAccessor.
- Parameters:
class – The target subclass of
GenericElement
elmfinders (Callable[[GenericElement], Iterable[T]]) – Functions that are called on the current element. Each returns an iterable of possible targets.
aslist (type[ElementList] | None) – If None, only a single element must match, which will be returned directly. If not None, must be a subclass of
ElementList
, which will be used to return a list of all matched objects.elmmatcher (Callable[[U, GenericElement], bool]) – Function that is called with the transformed target element and the current element to determine if the untransformed target should be accepted.
matchtransform (Callable[[T], U]) – Function that transforms a target so that it can be used by the matcher function.
class_ (type[T])
- Return type:
None
- elmfinders¶
- elmmatcher¶
- matchtransform¶
- class capellambse.model.common.accessors.DeepProxyAccessor¶
Bases:
DirectProxyAccessor
[T
]A DirectProxyAccessor that searches recursively through the tree.
- class capellambse.model.common.accessors.DeprecatedAccessor¶
Bases:
Accessor
[T
]Provides a deprecated alias to another attribute.
- alternative¶
- class capellambse.model.common.accessors.DirectProxyAccessor¶
Bases:
WritableAccessor
[T
],PhysicalAccessor
[T
]Creates proxy objects on the fly.
- __init__(class_, xtypes=None, *, aslist=None, follow_abstract=False, list_extra_args=None, rootelem=None, single_attr=None)¶
Create a DirectProxyAccessor.
- Parameters:
class – The proxy class.
xtypes (str | type[T] | Iterable[str | type[T]] | None) – The
xsi:type
(s) of the child element(s). If None, then the constructed proxy will be passed the original element instead of a child.aslist (type[ElementList] | None) – If None, only a single element must match, which will be returned directly. If not None, must be a subclass of
ElementList
, which will be used to return a list of all matched objects.follow_abstract (bool) – Follow the link in the
abstractType
XML attribute of each list member and instantiate that object instead. The default is to instantiate the child elements directly.list_extra_args (dict[str, Any] | None) – Extra arguments to pass to the
ElementList
constructor.rootelem (str | type[GenericElement] | Sequence[str | type[GenericElement]] | None) – A class or
xsi:type
(or list thereof) that defines the path from the current object’s XML element to the search root. If None, the current element will be used directly.single_attr (str | None) – If objects can be created with only a single attribute specified, this argument is the name of that attribute. This
create_singleattr()
.class_ (type[T])
- create(elmlist, /, *type_hints, **kw)¶
Create and return a new element of type
elmclass
.- Parameters:
elmlist (ElementListCouplingMixin) – The (coupled)
ElementList
to insert the new object into.type_hints (str | None) – Hints for finding the correct type of element to create. Can either be a full or shortened
xsi:type
string, or an abbreviation defined by the specific Accessor instance.kw (Any) – Initialize the properties of the new object. Depending on the object’s type, some attributes may be required.
- Return type:
T
- delete(elmlist, obj)¶
Delete the
obj
from the model.- Parameters:
elmlist (ElementListCouplingMixin)
obj (ModelObject)
- Return type:
None
- insert(elmlist, index, value)¶
Insert the
value
object into the model.The object must be inserted at an appropriate place, so that, if
elmlist
were to be created afresh,value
would show up at indexindex
.- Parameters:
elmlist (ElementListCouplingMixin)
index (int)
value (ModelObject | _NewObject)
- Return type:
None
- purge_references(obj, target)¶
Purge references to the given object from the model.
This method is called while deleting physical objects, in order to get rid of references to that object (and its descendants). Reference purging is done in two steps, which is why this method returns a context manager.
The first step, executed by the
__enter__
method, collects references to the target and ensures that deleting them would result in a valid model. If any validity constraints would be violated, an exception is raised to indicate as such, and the whole operation is aborted. This is also when the relevant “capellambse.delete” audit events are fired for each reference.Once all
__enter__
methods have been called, the target object is deleted from the model. Then all__exit__
methods are called, which triggers the actual deletion of all previously discovered references.As per the context manager protocol,
__exit__
will always be called after__enter__
, even if the operation is to be aborted. The__exit__
method must therefore inspect whether an exception was passed in or not in order to know whether the operation succeeded.In order to not confuse other context managers and keep the model consistent,
__exit__
must not raise any further exceptions. Exceptions should instead be logged to stderr, for example by using thelogging.Logger.exception()
facility.The
purge_references
method will only be called for Accessor instances that actually contain a reference.- Parameters:
obj (ModelObject) – The model object to purge references from.
target (ModelObject) – The object that is to be deleted; references to this object will be purged.
- Returns:
A context manager that deals with purging references in a transactional manner.
- Return type:
- Raises:
InvalidModificationError – Raised by the returned context manager’s
__enter__
method if the attempted modification would result in an invalid model. Note that it is generally preferred to allow the operation and take the necessary steps to keep the model consistent, if possible. This can be achieved for example by deleting dependent objects along with the original deletion target.Exception – Any exception may be raised before
__enter__
returns in order to abort the transaction and prevent theobj
from being deleted. No exceptions must be raised by__exit__
.
Examples
A simple implementation for purging a single object reference could look like this:
@contextlib.contextmanager def purge_references(self, obj, target): assert self.__get__(obj, type(obj)) == target sys.audit("capellambse.delete", obj, self.__name__, None) yield try: self.__delete__(obj) except Exception: LOGGER.exception("Could not purge a dangling reference")
- class capellambse.model.common.accessors.ElementListCouplingMixin¶
Bases:
ElementList
[T
],Generic
[T
]Couples an ElementList with an Accessor to enable write support.
This class is meant to be subclassed further, where the subclass has both this class and the originally intended one as base classes (but no other ones, i.e. there must be exactly two bases). The Accessor then inserts itself as the
_accessor
class variable on the new subclass. This allows the mixed-in methods to delegate actual model modifications to the Accessor.- __init__(*args, parent, fixed_length=0, **kw)¶
- Parameters:
args (Any)
parent (ModelObject)
fixed_length (int)
kw (Any)
- Return type:
None
- create(*type_hints, **kw)¶
Make a new model object (instance of GenericElement).
Instead of specifying the full
xsi:type
including the namespace, you can also pass in just the part after the:
separator. If this is unambiguous, the appropriate layer-specific type will be selected automatically.This method can be called with or without the
layertype
argument. If a layertype is not given, all layers will be tried to find an appropriatexsi:type
handler. Note that setting the layertype toNone
explicitly is different from not specifying it at all;None
tries only the “Transverse modelling” type elements.- Parameters:
type_hints (str | None) – Hints for finding the correct type of element to create. Can either be a full or shortened
xsi:type
string, or an abbreviation defined by the specific Accessor instance.kw (Any) – Initialize the properties of the new object. Depending on the object, some attributes may be required.
- Return type:
T
- create_singleattr(arg)¶
Make a new model object (instance of GenericElement).
This new object has only one interesting attribute.
See also
ElementListCouplingMixin.create()
More details on how elements are created.
WritableAccessor.create_singleattr()
The method to override in Accessors in order to implement this operation.
- Parameters:
arg (Any)
- Return type:
T
- class capellambse.model.common.accessors.IndexAccessor¶
Bases:
Accessor
[T
]Access a specific index in an ElementList of a fixed size.
- index¶
- wrapped¶
- exception capellambse.model.common.accessors.InvalidModificationError¶
Bases:
RuntimeError
Raised when a modification would result in an invalid model.
- class capellambse.model.common.accessors.LinkAccessor¶
Bases:
WritableAccessor
[T
],PhysicalAccessor
[T
]Accesses elements through reference elements.
- __init__(tag, xtype, /, *, aslist=None, attr, backattr=None, unique=True)¶
Create a LinkAccessor.
- Parameters:
tag (str | None) – The XML tag that the reference elements will have.
xtype (str | type[GenericElement]) – The
xsi:type
that the reference elements will have. This has no influence on the elements that are referenced.attr (str) – The attribute on the reference element that contains the actual link.
backattr (str | None) – An optional attribute on the reference element to store a reference back to the owner (parent) object.
aslist (type[ElementList] | None) – Optionally specify a different subclass of
ElementList
.unique (bool) – Enforce that each element may only appear once in the list. If a duplicate is attempted to be added, an exception will be raised. Note that this does not have an effect on lists already existing within the loaded model.
- Return type:
None
- delete(elmlist, obj)¶
Delete the
obj
from the model.- Parameters:
elmlist (ElementListCouplingMixin)
obj (ModelObject)
- Return type:
None
- insert(elmlist, index, value)¶
Insert the
value
object into the model.The object must be inserted at an appropriate place, so that, if
elmlist
were to be created afresh,value
would show up at indexindex
.- Parameters:
elmlist (ElementListCouplingMixin)
index (int)
value (ModelObject | _NewObject)
- Return type:
None
- purge_references(obj, target)¶
Purge references to the given object from the model.
This method is called while deleting physical objects, in order to get rid of references to that object (and its descendants). Reference purging is done in two steps, which is why this method returns a context manager.
The first step, executed by the
__enter__
method, collects references to the target and ensures that deleting them would result in a valid model. If any validity constraints would be violated, an exception is raised to indicate as such, and the whole operation is aborted. This is also when the relevant “capellambse.delete” audit events are fired for each reference.Once all
__enter__
methods have been called, the target object is deleted from the model. Then all__exit__
methods are called, which triggers the actual deletion of all previously discovered references.As per the context manager protocol,
__exit__
will always be called after__enter__
, even if the operation is to be aborted. The__exit__
method must therefore inspect whether an exception was passed in or not in order to know whether the operation succeeded.In order to not confuse other context managers and keep the model consistent,
__exit__
must not raise any further exceptions. Exceptions should instead be logged to stderr, for example by using thelogging.Logger.exception()
facility.The
purge_references
method will only be called for Accessor instances that actually contain a reference.- Parameters:
obj (ModelObject) – The model object to purge references from.
target (ModelObject) – The object that is to be deleted; references to this object will be purged.
- Returns:
A context manager that deals with purging references in a transactional manner.
- Return type:
- Raises:
InvalidModificationError – Raised by the returned context manager’s
__enter__
method if the attempted modification would result in an invalid model. Note that it is generally preferred to allow the operation and take the necessary steps to keep the model consistent, if possible. This can be achieved for example by deleting dependent objects along with the original deletion target.Exception – Any exception may be raised before
__enter__
returns in order to abort the transaction and prevent theobj
from being deleted. No exceptions must be raised by__exit__
.
Examples
A simple implementation for purging a single object reference could look like this:
@contextlib.contextmanager def purge_references(self, obj, target): assert self.__get__(obj, type(obj)) == target sys.audit("capellambse.delete", obj, self.__name__, None) yield try: self.__delete__(obj) except Exception: LOGGER.exception("Could not purge a dangling reference")
- unique¶
- exception capellambse.model.common.accessors.NonUniqueMemberError¶
Bases:
ValueError
Raised when a duplicate member is inserted into a list.
- property attr¶
- property parent¶
- property target¶
- class capellambse.model.common.accessors.ParentAccessor¶
Bases:
PhysicalAccessor
[T
]Accesses the parent XML element.
- class capellambse.model.common.accessors.PhysicalAccessor¶
Bases:
Accessor
[T
]Helper super class for accessors that work with real elements.
- __init__(class_, xtypes=None, *, aslist=None, list_extra_args=None)¶
- Parameters:
class_ (type[T])
xtypes (str | type[ModelObject] | Iterable[str | type[ModelObject]] | None)
aslist (type[ElementList[T]] | None)
- Return type:
None
- aslist: type[ElementList] | None¶
- class capellambse.model.common.accessors.PhysicalLinkEndsAccessor¶
Bases:
AttrProxyAccessor
[T
]- __init__(class_, attr, *, aslist)¶
Create an AttrProxyAccessor.
- Parameters:
class – The proxy class. Currently only used for type hints.
attr (str) – The XML attribute to handle.
aslist (type[ElementList]) – If None, the attribute contains at most one element reference, and either None or the constructed proxy will be returned. If not None, must be a subclass of
ElementList
. It will be used to return a list of all matched objects.list_extra_args – Extra arguments to pass to the
ElementList
constructor.class_ (type[T])
- Return type:
None
- attr¶
- purge_references(obj, target)¶
Purge references to the given object from the model.
This method is called while deleting physical objects, in order to get rid of references to that object (and its descendants). Reference purging is done in two steps, which is why this method returns a context manager.
The first step, executed by the
__enter__
method, collects references to the target and ensures that deleting them would result in a valid model. If any validity constraints would be violated, an exception is raised to indicate as such, and the whole operation is aborted. This is also when the relevant “capellambse.delete” audit events are fired for each reference.Once all
__enter__
methods have been called, the target object is deleted from the model. Then all__exit__
methods are called, which triggers the actual deletion of all previously discovered references.As per the context manager protocol,
__exit__
will always be called after__enter__
, even if the operation is to be aborted. The__exit__
method must therefore inspect whether an exception was passed in or not in order to know whether the operation succeeded.In order to not confuse other context managers and keep the model consistent,
__exit__
must not raise any further exceptions. Exceptions should instead be logged to stderr, for example by using thelogging.Logger.exception()
facility.The
purge_references
method will only be called for Accessor instances that actually contain a reference.- Parameters:
obj (ModelObject) – The model object to purge references from.
target (ModelObject) – The object that is to be deleted; references to this object will be purged.
- Returns:
A context manager that deals with purging references in a transactional manner.
- Return type:
- Raises:
InvalidModificationError – Raised by the returned context manager’s
__enter__
method if the attempted modification would result in an invalid model. Note that it is generally preferred to allow the operation and take the necessary steps to keep the model consistent, if possible. This can be achieved for example by deleting dependent objects along with the original deletion target.Exception – Any exception may be raised before
__enter__
returns in order to abort the transaction and prevent theobj
from being deleted. No exceptions must be raised by__exit__
.
Examples
A simple implementation for purging a single object reference could look like this:
@contextlib.contextmanager def purge_references(self, obj, target): assert self.__get__(obj, type(obj)) == target sys.audit("capellambse.delete", obj, self.__name__, None) yield try: self.__delete__(obj) except Exception: LOGGER.exception("Could not purge a dangling reference")
- class capellambse.model.common.accessors.ReferenceSearchingAccessor¶
Bases:
PhysicalAccessor
[T
]Searches for references to the current element elsewhere.
- __init__(class_, *attrs, aslist=None)¶
Create a ReferenceSearchingAccessor.
- Parameters:
class – The type of class to search for references on.
attrs (str) – The attributes of the target classes to search through.
aslist (type[ElementList] | None) – If None, only a single element must match, which will be returned directly. If not None, must be a subclass of
ElementList
, which will be used to return a list of all matched objects.class_ (type[T] | tuple[type[ModelObject], ...])
- Return type:
None
- target_classes: tuple[type[ModelObject], ...]¶
- class capellambse.model.common.accessors.RoleTagAccessor¶
Bases:
WritableAccessor
,PhysicalAccessor
- __init__(role_tag, classes=(), *, aslist=None, list_extra_args=None)¶
- Parameters:
role_tag (str)
classes (type[GenericElement] | Iterable[type[GenericElement]])
aslist (type[ElementList[T]] | None)
- Return type:
None
- classes¶
- create(elmlist, /, *type_hints, **kw)¶
Create and return a new element of type
elmclass
.- Parameters:
elmlist (ElementListCouplingMixin) – The (coupled)
ElementList
to insert the new object into.type_hints (str | None) – Hints for finding the correct type of element to create. Can either be a full or shortened
xsi:type
string, or an abbreviation defined by the specific Accessor instance.kw (Any) – Initialize the properties of the new object. Depending on the object’s type, some attributes may be required.
- Return type:
- delete(elmlist, obj)¶
Delete the
obj
from the model.- Parameters:
elmlist (ElementListCouplingMixin)
obj (ModelObject)
- Return type:
None
- insert(elmlist, index, value)¶
Insert the
value
object into the model.The object must be inserted at an appropriate place, so that, if
elmlist
were to be created afresh,value
would show up at indexindex
.- Parameters:
elmlist (ElementListCouplingMixin)
index (int)
value (ModelObject | _NewObject)
- Return type:
None
- purge_references(obj, target)¶
Purge references to the given object from the model.
This method is called while deleting physical objects, in order to get rid of references to that object (and its descendants). Reference purging is done in two steps, which is why this method returns a context manager.
The first step, executed by the
__enter__
method, collects references to the target and ensures that deleting them would result in a valid model. If any validity constraints would be violated, an exception is raised to indicate as such, and the whole operation is aborted. This is also when the relevant “capellambse.delete” audit events are fired for each reference.Once all
__enter__
methods have been called, the target object is deleted from the model. Then all__exit__
methods are called, which triggers the actual deletion of all previously discovered references.As per the context manager protocol,
__exit__
will always be called after__enter__
, even if the operation is to be aborted. The__exit__
method must therefore inspect whether an exception was passed in or not in order to know whether the operation succeeded.In order to not confuse other context managers and keep the model consistent,
__exit__
must not raise any further exceptions. Exceptions should instead be logged to stderr, for example by using thelogging.Logger.exception()
facility.The
purge_references
method will only be called for Accessor instances that actually contain a reference.- Parameters:
obj (ModelObject) – The model object to purge references from.
target (ModelObject) – The object that is to be deleted; references to this object will be purged.
- Returns:
A context manager that deals with purging references in a transactional manner.
- Return type:
- Raises:
InvalidModificationError – Raised by the returned context manager’s
__enter__
method if the attempted modification would result in an invalid model. Note that it is generally preferred to allow the operation and take the necessary steps to keep the model consistent, if possible. This can be achieved for example by deleting dependent objects along with the original deletion target.Exception – Any exception may be raised before
__enter__
returns in order to abort the transaction and prevent theobj
from being deleted. No exceptions must be raised by__exit__
.
Examples
A simple implementation for purging a single object reference could look like this:
@contextlib.contextmanager def purge_references(self, obj, target): assert self.__get__(obj, type(obj)) == target sys.audit("capellambse.delete", obj, self.__name__, None) yield try: self.__delete__(obj) except Exception: LOGGER.exception("Could not purge a dangling reference")
- role_tag¶
- class capellambse.model.common.accessors.SpecificationAccessor¶
Bases:
Accessor
[_Specification
]Provides access to linked specifications.
- class capellambse.model.common.accessors.TypecastAccessor¶
Bases:
WritableAccessor
[T
],PhysicalAccessor
[T
]Changes the static type of the value of another accessor.
This is useful for when a class has an attribute that is polymorphic, but the accessor should always return a specific subclass.
At runtime, this Accessor mostly behaves like a simple alias (without performing any runtime type checks or conversions). When creating new objects, it will only allow to create objects of the specified type.
- aslist: type[ElementListCouplingMixin] | None¶
- create(elmlist, /, *type_hints, **kw)¶
Create and return a new element of type
elmclass
.- Parameters:
elmlist (ElementListCouplingMixin) – The (coupled)
ElementList
to insert the new object into.type_hints (str | None) – Hints for finding the correct type of element to create. Can either be a full or shortened
xsi:type
string, or an abbreviation defined by the specific Accessor instance.kw (Any) – Initialize the properties of the new object. Depending on the object’s type, some attributes may be required.
- Return type:
T
- delete(elmlist, obj)¶
Delete the
obj
from the model.- Parameters:
elmlist (ElementListCouplingMixin)
obj (ModelObject)
- Return type:
None
- insert(elmlist, index, value)¶
Insert the
value
object into the model.The object must be inserted at an appropriate place, so that, if
elmlist
were to be created afresh,value
would show up at indexindex
.- Parameters:
elmlist (ElementListCouplingMixin)
index (int)
value (ModelObject | _NewObject)
- Return type:
None
- purge_references(obj, target)¶
Purge references to the given object from the model.
This method is called while deleting physical objects, in order to get rid of references to that object (and its descendants). Reference purging is done in two steps, which is why this method returns a context manager.
The first step, executed by the
__enter__
method, collects references to the target and ensures that deleting them would result in a valid model. If any validity constraints would be violated, an exception is raised to indicate as such, and the whole operation is aborted. This is also when the relevant “capellambse.delete” audit events are fired for each reference.Once all
__enter__
methods have been called, the target object is deleted from the model. Then all__exit__
methods are called, which triggers the actual deletion of all previously discovered references.As per the context manager protocol,
__exit__
will always be called after__enter__
, even if the operation is to be aborted. The__exit__
method must therefore inspect whether an exception was passed in or not in order to know whether the operation succeeded.In order to not confuse other context managers and keep the model consistent,
__exit__
must not raise any further exceptions. Exceptions should instead be logged to stderr, for example by using thelogging.Logger.exception()
facility.The
purge_references
method will only be called for Accessor instances that actually contain a reference.- Parameters:
obj (ModelObject) – The model object to purge references from.
target (ModelObject) – The object that is to be deleted; references to this object will be purged.
- Returns:
A context manager that deals with purging references in a transactional manner.
- Return type:
- Raises:
InvalidModificationError – Raised by the returned context manager’s
__enter__
method if the attempted modification would result in an invalid model. Note that it is generally preferred to allow the operation and take the necessary steps to keep the model consistent, if possible. This can be achieved for example by deleting dependent objects along with the original deletion target.Exception – Any exception may be raised before
__enter__
returns in order to abort the transaction and prevent theobj
from being deleted. No exceptions must be raised by__exit__
.
Examples
A simple implementation for purging a single object reference could look like this:
@contextlib.contextmanager def purge_references(self, obj, target): assert self.__get__(obj, type(obj)) == target sys.audit("capellambse.delete", obj, self.__name__, None) yield try: self.__delete__(obj) except Exception: LOGGER.exception("Could not purge a dangling reference")
- class capellambse.model.common.accessors.WritableAccessor¶
Bases:
Accessor
[T
]An Accessor that also provides write support on lists it returns.
- __init__(*args, aslist, single_attr=None, **kw)¶
- Parameters:
args (Any)
aslist (type[ElementList] | None)
single_attr (str | None)
kw (Any)
- Return type:
None
- aslist: type[ElementListCouplingMixin] | None¶
- create(elmlist, /, *type_hints, **kw)¶
Create and return a new element of type
elmclass
.- Parameters:
elmlist (ElementListCouplingMixin) – The (coupled)
ElementList
to insert the new object into.type_hints (str | None) – Hints for finding the correct type of element to create. Can either be a full or shortened
xsi:type
string, or an abbreviation defined by the specific Accessor instance.kw (Any) – Initialize the properties of the new object. Depending on the object’s type, some attributes may be required.
- Return type:
T
- create_singleattr(elmlist, arg, /)¶
Create an element that only has a single attribute of interest.
- Parameters:
elmlist (ElementListCouplingMixin)
arg (Any)
- Return type:
T
- delete(elmlist, obj)¶
Delete the
obj
from the model.- Parameters:
elmlist (ElementListCouplingMixin)
obj (ModelObject)
- Return type:
None
- insert(elmlist, index, value)¶
Insert the
value
object into the model.The object must be inserted at an appropriate place, so that, if
elmlist
were to be created afresh,value
would show up at indexindex
.- Parameters:
elmlist (ElementListCouplingMixin)
index (int)
value (ModelObject | _NewObject)
- Return type:
None
- purge_references(obj, target)¶
Purge references to the given object from the model.
This method is called while deleting physical objects, in order to get rid of references to that object (and its descendants). Reference purging is done in two steps, which is why this method returns a context manager.
The first step, executed by the
__enter__
method, collects references to the target and ensures that deleting them would result in a valid model. If any validity constraints would be violated, an exception is raised to indicate as such, and the whole operation is aborted. This is also when the relevant “capellambse.delete” audit events are fired for each reference.Once all
__enter__
methods have been called, the target object is deleted from the model. Then all__exit__
methods are called, which triggers the actual deletion of all previously discovered references.As per the context manager protocol,
__exit__
will always be called after__enter__
, even if the operation is to be aborted. The__exit__
method must therefore inspect whether an exception was passed in or not in order to know whether the operation succeeded.In order to not confuse other context managers and keep the model consistent,
__exit__
must not raise any further exceptions. Exceptions should instead be logged to stderr, for example by using thelogging.Logger.exception()
facility.The
purge_references
method will only be called for Accessor instances that actually contain a reference.- Parameters:
obj (ModelObject) – The model object to purge references from.
target (ModelObject) – The object that is to be deleted; references to this object will be purged.
- Returns:
A context manager that deals with purging references in a transactional manner.
- Return type:
- Raises:
InvalidModificationError – Raised by the returned context manager’s
__enter__
method if the attempted modification would result in an invalid model. Note that it is generally preferred to allow the operation and take the necessary steps to keep the model consistent, if possible. This can be achieved for example by deleting dependent objects along with the original deletion target.Exception – Any exception may be raised before
__enter__
returns in order to abort the transaction and prevent theobj
from being deleted. No exceptions must be raised by__exit__
.
Examples
A simple implementation for purging a single object reference could look like this:
@contextlib.contextmanager def purge_references(self, obj, target): assert self.__get__(obj, type(obj)) == target sys.audit("capellambse.delete", obj, self.__name__, None) yield try: self.__delete__(obj) except Exception: LOGGER.exception("Could not purge a dangling reference")
capellambse.model.common.element module¶
- class capellambse.model.common.element.CachedElementList¶
Bases:
ElementList
[T
],Generic
[T
]An ElementList that caches the constructed proxies by UUID.
- __init__(model, elements, elemclass, *, cacheattr=None, **kw)¶
Create a CachedElementList.
- Parameters:
model (MelodyModel) – The model that all elements are a part of.
elemclass (type[T]) – The
GenericElement
subclass to use for reconstructing elements.cacheattr (str | None) – The attribute on the
model
to use as cache.kw (Any)
- Return type:
None
- class capellambse.model.common.element.ElementList¶
Bases:
MutableSequence
,Generic
[T
]Provides access to elements without affecting the underlying model.
- __init__(model, elements, elemclass=None, *, mapkey=None, mapvalue=None)¶
- filter(predicate)¶
Filter this list with a custom predicate.
The predicate may be the name of an attribute or a callable, which will be called on each list item. If the attribute value or the callable’s return value is truthy, the item is included in the resulting list.
When specifying the name of an attribute, nested attributes can be chained using
.
, like"parent.name"
(which would pick all elements whoseparent
has a non-emptyname
).- Parameters:
- Return type:
ElementList[T]
- insert(index, value)¶
S.insert(index, value) – insert value before index
- Parameters:
index (int)
value (T)
- Return type:
None
- items()¶
- Return type:
- keys()¶
- Return type:
- map(attr)¶
Apply a function to each element in this list.
If the argument is a string, it is interpreted as an attribute name, and the value of that attribute is returned for each element. Nested attribute names can be chained with
.
.If the argument is a callable, it is called for each element, and the return value is included in the result. If the callable returns a sequence, the sequence is flattened into the result.
Duplicate values and Nones are always filtered out.
It is an error if a callable returns something that is not a model element or a flat sequence of model elements.
- Parameters:
attr (str | _MapFunction[T])
- Return type:
- values()¶
- Return type:
ElementList[T]
- class capellambse.model.common.element.ElementListMapItemsView¶
Bases:
Sequence
[Tuple
[Any
,Any
]],Generic
[T
]- __init__(parent, /)¶
- Return type:
None
- class capellambse.model.common.element.ElementListMapKeyView¶
Bases:
Sequence
- __init__(parent, /)¶
- Return type:
None
- class capellambse.model.common.element.GenericElement¶
Bases:
object
Provides high-level access to a single model element.
- __init__(model, parent, xmltag=None, /, **kw)¶
- Parameters:
model (MelodyModel)
parent (_Element)
xmltag (str | None)
kw (Any)
- Return type:
None
- applied_property_value_groups¶
The applied property value groups of this GenericElement.
- applied_property_values¶
The applied property values of this GenericElement.
- description¶
- property diagrams¶
- filtering_criteria¶
The filtering criteria of this GenericElement.
- classmethod from_model(model, element)¶
Wrap an existing model object.
- Parameters:
model (MelodyModel) – The MelodyModel instance
element (_Element) – The XML element to wrap
- Returns:
An instance of GenericElement (or a more appropriate subclass, if any) that wraps the given XML element.
- Return type:
- name¶
- parent: ParentAccessor¶
The parent of this GenericElement.
- property progress_status: AttributeProperty | str¶
- property_value_groups¶
The property value groups of this GenericElement.
- property_values¶
The property values of this GenericElement.
- pvmt¶
The pvmt of this GenericElement.
- requirements¶
The requirements of this GenericElement.
- summary¶
- traces¶
The traces of this GenericElement.
- uuid¶
- property xtype¶
- class capellambse.model.common.element.MixedElementList¶
Bases:
ElementList
[GenericElement
]ElementList that handles proxies using
XTYPE_HANDLERS
.
- class capellambse.model.common.element.ModelObject¶
Bases:
Protocol
A class that wraps a specific model object.
Most of the time, you’ll want to subclass the concrete
GenericElement
class. However, some special classes (e.g. AIRD diagrams) provide a compatible interface, but it doesn’t make sense to wrap a specific XML element. This protocol class is used in type annotations to catch both “normal” GenericElement subclasses and the mentioned special cases.- __init__(model, parent, xmltag, /, **kw)¶
Create a new model object.
- Parameters:
model (MelodyModel) – The model instance.
parent (_Element) – The parent XML element below which to create a new object.
kw (Any) – Any additional arguments will be used to populate the instance attributes. Note that some attributes may be required by specific element types at construction time (commonly e.g.
uuid
).xmltag (str | None)
- Return type:
None
- classmethod from_model(model, element)¶
Instantiate a ModelObject from existing model elements.
- Parameters:
model (MelodyModel)
element (Any)
- Return type:
capellambse.model.common.properties module¶
- class capellambse.model.common.properties.AttributeProperty¶
Bases:
object
A property that forwards access to the underlying XML element.
- NOT_OPTIONAL = <object object>¶
- __init__(attribute, *, returntype=<class 'str'>, optional=False, default=None, writable=True, __doc__=None)¶
Create an AttributeProperty.
- Parameters:
attribute (str) – The attribute on the XML element to handle.
returntype (Callable[[str], Any]) – The type to return the result as. Must accept a single
str
as argument.optional (bool) – If False (default) and the XML attribute does not exist, an AttributeError is raised. Otherwise a default value is returned.
default (Any) – A new-style format string to use as fallback value. You can access the object instance as
self
and the XML element asxml
.writable (bool) – Whether to allow modifying the XML attribute.
__doc__ (str | None)
- Return type:
None
- attribute¶
- default¶
- returntype¶
- writable¶
- class capellambse.model.common.properties.BooleanAttributeProperty¶
Bases:
AttributeProperty
An AttributeProperty that works with booleans.
- __init__(attribute, *, writable=True, __doc__=None)¶
Create an AttributeProperty.
- Parameters:
attribute (str) – The attribute on the XML element to handle.
returntype – The type to return the result as. Must accept a single
str
as argument.optional – If False (default) and the XML attribute does not exist, an AttributeError is raised. Otherwise a default value is returned.
default – A new-style format string to use as fallback value. You can access the object instance as
self
and the XML element asxml
.writable (bool) – Whether to allow modifying the XML attribute.
__doc__ (str | None)
- Return type:
None
- attribute¶
- default¶
- returntype¶
- writable¶
- class capellambse.model.common.properties.DatetimeAttributeProperty¶
Bases:
AttributeProperty
An AttributeProperty that stores a datetime.
The value stored in the XML will be formatted as required by Capella. This format is the ISO8601 format with millisecond precision, but no
:
in the time zone specification.- __init__(attribute, *, optional=True, writable=True, __doc__=None)¶
Create an AttributeProperty.
- Parameters:
attribute (str) – The attribute on the XML element to handle.
returntype – The type to return the result as. Must accept a single
str
as argument.optional (bool) – If False (default) and the XML attribute does not exist, an AttributeError is raised. Otherwise a default value is returned.
default – A new-style format string to use as fallback value. You can access the object instance as
self
and the XML element asxml
.writable (bool) – Whether to allow modifying the XML attribute.
__doc__ (str | None)
- Return type:
None
- format¶
- re_get = re.compile('(?<=[+-]\\d\\d)(?=\\d\\d$)')¶
- re_set = re.compile('(?<=[+-]\\d\\d):(?=\\d\\d$)')¶
- class capellambse.model.common.properties.EnumAttributeProperty¶
Bases:
AttributeProperty
An AttributeProperty whose values are determined by an Enum.
This works in much the same way as the standard AttributeProperty, except that the returned and consumed values are not simple strings, but members of the Enum that was passed into the constructor.
Usually it is expected that the enum members will be directly assigned to this property. However it is also possible to assign a
str
instead. In this case, the string will be taken to be an enum member’s name. In both cases, the enum member’s value will be placed in the underlying XML attribute.If the XML attribute contains a value that does not correspond to any of the Enum’s members, a KeyError will be raised. If the attribute is completely missing from the XML and there was no
default=
value set during construction, this property will returnNone
.- __init__(attribute, enumcls, *args, default=None, **kw)¶
Create an EnumAttributeProperty.
- Parameters:
attribute (str) – The attribute on the XML element to handle.
enumcls (type[Enum]) – The
enum.Enum
subclass to use. The class’ members’ values are used as the possible values for the XML attribute.default (str | Enum | None) – The default value to return if the attribute is not present in the XML. If None, an AttributeError will be raised instead.
args (Any)
kw (Any)
- Return type:
None
- enumcls¶
- class capellambse.model.common.properties.HTMLAttributeProperty¶
Bases:
AttributeProperty
An AttributeProperty that gracefully handles HTML-in-XML.
- __init__(attribute, *, optional=False, writable=True, __doc__=None)¶
Create an AttributeProperty.
- Parameters:
attribute (str) – The attribute on the XML element to handle.
returntype – The type to return the result as. Must accept a single
str
as argument.optional (bool) – If False (default) and the XML attribute does not exist, an AttributeError is raised. Otherwise a default value is returned.
default – A new-style format string to use as fallback value. You can access the object instance as
self
and the XML element asxml
.writable (bool) – Whether to allow modifying the XML attribute.
__doc__ (str | None)
- Return type:
None
- attribute¶
- default¶
- returntype¶
- writable¶
- class capellambse.model.common.properties.NumericAttributeProperty¶
Bases:
AttributeProperty
Attribute property that handles (possibly infinite) numeric values.
Positive infinity is stored in Capella XML as *. This class takes care of converting to and from that value when setting or retrieving the value.
Note that there is currently no representation of negative infinity, which is why
-inf
is rejected with aValueError
.NaN
values are rejected with a ValueError as well.- __init__(attribute, *, optional=False, default=None, allow_float=True, writable=True, __doc__=None)¶
Create an AttributeProperty.
- Parameters:
attribute (str) – The attribute on the XML element to handle.
returntype – The type to return the result as. Must accept a single
str
as argument.optional (bool) – If False (default) and the XML attribute does not exist, an AttributeError is raised. Otherwise a default value is returned.
default (int | float | None) – A new-style format string to use as fallback value. You can access the object instance as
self
and the XML element asxml
.writable (bool) – Whether to allow modifying the XML attribute.
allow_float (bool)
__doc__ (str | None)
- Return type:
None
- attribute¶
- default¶
- returntype¶
- writable¶