capellambse package¶
The capellambse package.
- capellambse.load_model_extensions()¶
Load all model extensions.
This function loads all entry points in the group
capellambse.model_extensions
and executes them.It is automatically called when loading a model. Calling it more than once has no effect, so it is safe (although not necessary) to explicitly call this function before loading a model.
- Return type:
None
Subpackages¶
- capellambse.aird package
- capellambse.diagram package
- capellambse.extensions package
- Subpackages
- capellambse.extensions.metrics package
- capellambse.extensions.reqif package
AbstractRequirementsAttribute
AbstractRequirementsRelation
AbstractType
AttributeAccessor
AttributeDefinition
AttributeDefinitionEnumeration
BooleanValueAttribute
CapellaIncomingRelation
CapellaModule
CapellaOutgoingRelation
CapellaTypesFolder
DataTypeDefinition
DateValueAttribute
ElementRelationAccessor
EnumValue
EnumerationDataTypeDefinition
EnumerationValueAttribute
Folder
IntegerValueAttribute
InternalRelation
ModuleType
RealValueAttribute
RelationType
RelationsList
ReqIFElement
Requirement
RequirementType
RequirementsRelationAccessor
StringValueAttribute
init()
- Submodules
- capellambse.extensions.reqif.exporter module
- Submodules
- capellambse.extensions.filtering module
- capellambse.extensions.pvmt module
- Subpackages
- capellambse.filehandler package
FileHandler
TransactionClosedError
get_filehandler()
- Submodules
- capellambse.filehandler.abc module
- capellambse.filehandler.git module
GitFileHandler
GitFileHandler.__init__()
GitFileHandler.cache_dir
GitFileHandler.get_model_info()
GitFileHandler.identity_file
GitFileHandler.iterdir()
GitFileHandler.known_hosts_file
GitFileHandler.open()
GitFileHandler.password
GitFileHandler.rootdir
GitFileHandler.shallow
GitFileHandler.username
GitFileHandler.write_transaction()
GitPath
- capellambse.filehandler.git_askpass module
- capellambse.filehandler.gitlab_artifacts module
- capellambse.filehandler.http module
- capellambse.filehandler.local module
- capellambse.filehandler.memory module
- capellambse.filehandler.zip module
- capellambse.loader package
- Submodules
- capellambse.loader.core module
CorruptModelError
FragmentType
MelodyLoader
MelodyLoader.__init__()
MelodyLoader.activate_viewpoint()
MelodyLoader.check_duplicate_uuids()
MelodyLoader.create_link()
MelodyLoader.filehandler
MelodyLoader.find_by_xsi_type()
MelodyLoader.find_fragment()
MelodyLoader.follow_link()
MelodyLoader.follow_links()
MelodyLoader.generate_uuid()
MelodyLoader.get_model_info()
MelodyLoader.idcache_index()
MelodyLoader.idcache_rebuild()
MelodyLoader.idcache_remove()
MelodyLoader.iterall()
MelodyLoader.iterall_xt()
MelodyLoader.iterancestors()
MelodyLoader.iterchildren_xt()
MelodyLoader.iterdescendants()
MelodyLoader.iterdescendants_xt()
MelodyLoader.new_uuid()
MelodyLoader.referenced_viewpoints()
MelodyLoader.save()
MelodyLoader.update_namespaces()
MelodyLoader.write_tmp_project_dir()
MelodyLoader.xpath()
MelodyLoader.xpath2()
ModelFile
- capellambse.loader.exs module
- capellambse.loader.filehandler module
- capellambse.loader.modelinfo module
- capellambse.loader.xmltools module
- capellambse.model package
ElementList
GenericElement
GenericElement.__init__()
GenericElement.applied_property_value_groups
GenericElement.applied_property_values
GenericElement.constraints
GenericElement.description
GenericElement.diagrams
GenericElement.filtering_criteria
GenericElement.from_model()
GenericElement.name
GenericElement.parent
GenericElement.progress_status
GenericElement.property_value_groups
GenericElement.property_values
GenericElement.pvmt
GenericElement.requirements
GenericElement.summary
GenericElement.traces
GenericElement.uuid
GenericElement.xtype
MelodyModel
MelodyModel.__init__()
MelodyModel.activate_viewpoint()
MelodyModel.by_uuid()
MelodyModel.description_badge
MelodyModel.diagram_cache
MelodyModel.diagrams
MelodyModel.enumeration_property_types
MelodyModel.filtering_model
MelodyModel.find_references()
MelodyModel.from_model()
MelodyModel.info
MelodyModel.la
MelodyModel.name
MelodyModel.oa
MelodyModel.pa
MelodyModel.parent
MelodyModel.property_value_packages
MelodyModel.referenced_viewpoints()
MelodyModel.resources
MelodyModel.sa
MelodyModel.save()
MelodyModel.search()
MelodyModel.update_diagram_cache()
MelodyModel.uuid
NonUniqueMemberError
- Subpackages
- capellambse.model.common package
- capellambse.model.crosslayer package
BaseArchitectureLayer
- Subpackages
- Submodules
- capellambse.model.crosslayer.capellacommon module
- capellambse.model.crosslayer.capellacore module
- capellambse.model.crosslayer.cs module
- capellambse.model.crosslayer.fa module
- capellambse.model.crosslayer.interaction module
- capellambse.model.crosslayer.modellingcore module
- capellambse.model.layers package
- Submodules
- capellambse.model.diagram module
- capellambse.model.modeltypes module
AccessPolicy
AggregationKind
BinaryOperator
CatalogElementKind
ChangeEventKind
CollectionKind
CommunicationLinkKind
CommunicationLinkKind.ACCESS
CommunicationLinkKind.ACQUIRE
CommunicationLinkKind.CALL
CommunicationLinkKind.CONSUME
CommunicationLinkKind.EXECUTE
CommunicationLinkKind.PRODUCE
CommunicationLinkKind.RECEIVE
CommunicationLinkKind.SEND
CommunicationLinkKind.TRANSMIT
CommunicationLinkKind.UNSET
CommunicationLinkKind.WRITE
CommunicationLinkProtocol
ComponentExchangeKind
ComponentPortKind
ConfigurationItemKind
ControlNodeKind
DiagramType
DiagramType.CC
DiagramType.CDB
DiagramType.CDI
DiagramType.CEI
DiagramType.CIBD
DiagramType.CII
DiagramType.CM
DiagramType.COC
DiagramType.CRB
DiagramType.CRI
DiagramType.CRR
DiagramType.CSA
DiagramType.EAB
DiagramType.ES
DiagramType.FS
DiagramType.ID
DiagramType.IDB
DiagramType.IS
DiagramType.LAB
DiagramType.LCBD
DiagramType.LDFB
DiagramType.LFBD
DiagramType.LFCD
DiagramType.MB
DiagramType.MCB
DiagramType.MSM
DiagramType.OAB
DiagramType.OABD
DiagramType.OAIB
DiagramType.OAS
DiagramType.OCB
DiagramType.OEBD
DiagramType.OES
DiagramType.OPD
DiagramType.ORB
DiagramType.PAB
DiagramType.PCBD
DiagramType.PD
DiagramType.PDFB
DiagramType.PFBD
DiagramType.PFCD
DiagramType.PPD
DiagramType.SAB
DiagramType.SDFB
DiagramType.SFBD
DiagramType.SFCD
DiagramType.UNKNOWN
ElementKind
ExchangeMechanism
FunctionKind
FunctionalChainKind
InteractionOperatorKind
InteractionOperatorKind.ALT
InteractionOperatorKind.ASSERT
InteractionOperatorKind.CONSIDER
InteractionOperatorKind.CRITICAL
InteractionOperatorKind.IGNORE
InteractionOperatorKind.LOOP
InteractionOperatorKind.NEG
InteractionOperatorKind.OPT
InteractionOperatorKind.PAR
InteractionOperatorKind.SEQ
InteractionOperatorKind.STRICT
InteractionOperatorKind.UNSET
MessageKind
NumericTypeKind
ObjectNodeKind
ObjectNodeOrderingKind
OrientationPortKind
ParameterDirection
ParameterEffectKind
PassingMode
PhysicalComponentKind
PhysicalComponentKind.DATA
PhysicalComponentKind.FACILITIES
PhysicalComponentKind.FIRMWARE
PhysicalComponentKind.HARDWARE
PhysicalComponentKind.HARDWARE_COMPUTER
PhysicalComponentKind.MATERIALS
PhysicalComponentKind.PERSON
PhysicalComponentKind.PROCESSES
PhysicalComponentKind.SERVICES
PhysicalComponentKind.SOFTWARE
PhysicalComponentKind.SOFTWARE_APPLICATION
PhysicalComponentKind.SOFTWARE_DEPLOYMENT_UNIT
PhysicalComponentKind.SOFTWARE_EXECUTION_UNIT
PhysicalComponentKind.UNSET
PhysicalComponentNature
RateKind
ScenarioKind
SynchronismKind
TimeEventKind
TransitionKind
UnaryOperator
UnionKind
VisibilityKind
_StringyEnumMixin
- capellambse.pvmt package
- Submodules
- capellambse.pvmt.core module
- capellambse.pvmt.exceptions module
- capellambse.pvmt.model module
- capellambse.pvmt.types module
- capellambse.pvmt.validation module
- capellambse.svg package
- Submodules
- capellambse.svg.decorations module
- capellambse.svg.drawing module
- capellambse.svg.generate module
- capellambse.svg.helpers module
- capellambse.svg.style module
- capellambse.svg.symbols module
and_control_node_symbol()
arrow_mark()
capability_symbol()
class_symbol()
component_exchange_symbol()
component_port_symbol()
diamond_mark()
entity_symbol()
error_symbol()
filled_diamond_mark()
final_state_symbol()
fine_arrow_mark()
function_symbol()
functional_exchange_symbol()
generalization_mark()
initial_pseudo_state_symbol()
iterate_control_node_symbol()
logical_actor_symbol()
logical_component_symbol()
logical_function_symbol()
logical_human_actor_symbol()
logical_human_component_symbol()
mission_symbol()
mode_symbol()
operational_activity_symbol()
operational_actor_box_symbol()
operational_actor_symbol()
operational_capability_symbol()
operational_exchange_symbol()
or_control_node_symbol()
physical_behavior_actor_symbol()
physical_behavior_component_symbol()
physical_behavior_human_actor_symbol()
physical_behavior_human_component_symbol()
physical_component_symbol()
physical_function_symbol()
physical_link_symbol()
physical_node_actor_symbol()
physical_node_component_symbol()
physical_node_human_actor_symbol()
physical_node_human_component_symbol()
port_symbol()
representation_link_symbol()
requirement_symbol()
standalone_stick_figure_symbol()
state_symbol()
stick_figure_symbol()
system_actor_symbol()
system_component_symbol()
system_function_symbol()
system_human_actor_symbol()
terminate_pseudo_state_symbol()
Submodules¶
capellambse.auditing module¶
- class capellambse.auditing.AttributeAuditor¶
Bases:
object
Audits access to attributes of ModelElements.
Warning
This will permanently add an audit hook to the global hook table. The auditor will keep the model alive, which may consume excessive memory. To avoid this, call the auditor object’s
detach()
method once you are done with it. This is automatically done if you use it as a context manager.Examples
>>> auditor = AttributeAuditor(model, {"name", "description"}) >>> print(model.la.all_components[0].name) Hogwarts >>> auditor.recorded_ids {'0d2edb8f-fa34-4e73-89ec-fb9a63001440'} >>> # Cleanup >>> auditor.detach()
>>> with AttributeAuditor(model, {"name", "description"}) as recorded_ids: ... print(model.la.all_components[0].name) ... Hogwarts >>> recorded_ids {'0d2edb8f-fa34-4e73-89ec-fb9a63001440'}
- __init__(model, attrs=())¶
- Parameters:
model (MelodyModel)
- Return type:
None
- detach()¶
- Return type:
None
- class capellambse.auditing.WriteProtector¶
Bases:
object
Prevents accidental modifications to a model.
This class intentionally has very limited features. It is intended as inspiration and guidance for more specific classes that make more sophisticated use of audit events.
This class also contains a publicly usable set of events that signify changes to the model.
- __init__(model)¶
- Parameters:
model (MelodyModel)
- Return type:
None
- detach()¶
- Return type:
None
capellambse.cli_helpers module¶
Helpers for working with models in CLI scripts.
- capellambse.cli_helpers.ModelCLI(*__, **_)¶
Raise a dependency error.
- capellambse.cli_helpers.ModelInfoCLI(*__, **_)¶
Raise a dependency error.
- capellambse.cli_helpers.enumerate_known_models()¶
Enumerate the models that are found in the
known_models
folders.Two places are searched for models: The known_models folder in the user’s configuration directory, and the known_models folder in the installed
capellambse
package.Run the following command to print the location of the user’s known_models folder:
python -m capellambse.cli_helpers
In order to make a custom model known, place a JSON file in one of these known_models folders. It should contain a dictionary with the keyword arguments to
MelodyModel
- specifically it needs apath
, optionally anentrypoint
, and any additional arguments that the underlyingFileHandler
might need to gain access to the model.Files in the user’s configuration directory take precedence over files in the package directory. If a file with the same name exists in both places, the one in the user’s configuration directory will be used.
Be aware that relative paths in the JSON will be interpreted relative to the current working directory.
- Return type:
- capellambse.cli_helpers.loadcli(value)¶
Load a model from a file or JSON string.
This function works like
loadinfo()
, and also loads the model for convenience.- Parameters:
value (str | PathLike[str]) – As described for
loadinfo()
.- Returns:
The loaded model, as described by the value.
- Return type:
Examples
def main(): model = capellambse.loadcli(sys.argv[1])
- capellambse.cli_helpers.loadinfo(value)¶
Load information about how to load a model as dict.
- Parameters:
One of the following:
A str or PathLike pointing to an
.aird
fileA str or PathLike pointing to a
.json
file, which contains the arguments to instantiate aMelodyModel
The contents of such a JSON file (as string)
- Returns:
A dict with information about how to load a
MelodyModel
.- Return type:
- Raises:
TypeError – If the value cannot be parsed as described above.
ValueError – If the value looks like a “known model” name, but the name is not defined.
Examples
def main(): modelinfo = capellambse.loadinfo(sys.argv[1]) # change any options, for example: modelinfo["diagram_cache"] = "/tmp/diagrams" model = MelodyModel(**modelinfo)
capellambse.decl module¶
Support for YAML-based declarative modelling.
A YAML-based approach to describing how to create and modify
capellambse
compatible models.
For an in-depth explanation, please refer to the full documentation about declarative modelling.
- capellambse.decl.NewObject¶
alias of
_NewObject
- class capellambse.decl.UUIDReference¶
Bases:
object
References a model object by its UUID.
- __init__(uuid)¶
- Parameters:
uuid (UUIDString)
- Return type:
None
- uuid: UUIDString¶
- exception capellambse.decl.UnfulfilledPromisesError¶
Bases:
RuntimeError
A promise could not be fulfilled.
This exception is raised when a promise is referenced via
!promise
, but it is never fulfilled by declaring an object with the samepromise_id
.
- class capellambse.decl.YDMDumper¶
Bases:
SafeDumper
A YAML dumper with extensions for declarative modelling.
- yaml_representers = {<class 'NoneType'>: <function SafeRepresenter.represent_none>, <class 'bool'>: <function SafeRepresenter.represent_bool>, <class 'bytes'>: <function SafeRepresenter.represent_binary>, <class 'capellambse.decl.FindBy'>: <function YDMDumper.represent_findby>, <class 'capellambse.decl.Promise'>: <function YDMDumper.represent_promise>, <class 'capellambse.decl.UUIDReference'>: <function YDMDumper.represent_uuidref>, <class 'capellambse.model.common.accessors._NewObject'>: <function YDMDumper.represent_newobj>, <class 'datetime.date'>: <function SafeRepresenter.represent_date>, <class 'datetime.datetime'>: <function SafeRepresenter.represent_datetime>, <class 'dict'>: <function SafeRepresenter.represent_dict>, <class 'float'>: <function SafeRepresenter.represent_float>, <class 'int'>: <function SafeRepresenter.represent_int>, <class 'list'>: <function SafeRepresenter.represent_list>, <class 'set'>: <function SafeRepresenter.represent_set>, <class 'str'>: <function SafeRepresenter.represent_str>, <class 'tuple'>: <function SafeRepresenter.represent_list>, None: <function SafeRepresenter.represent_undefined>}¶
- class capellambse.decl.YDMLoader¶
Bases:
SafeLoader
A YAML loader with extensions for declarative modelling.
- construct_newobj(node)¶
- Parameters:
node (Node)
- Return type:
_NewObject
- construct_uuidref(node)¶
- Parameters:
node (Node)
- Return type:
- yaml_constructors = {'!find': <function YDMLoader.construct_findby>, '!new_object': <function YDMLoader.construct_newobj>, '!promise': <function YDMLoader.construct_promise>, '!uuid': <function YDMLoader.construct_uuidref>, 'tag:yaml.org,2002:binary': <function SafeConstructor.construct_yaml_binary>, 'tag:yaml.org,2002:bool': <function SafeConstructor.construct_yaml_bool>, 'tag:yaml.org,2002:float': <function SafeConstructor.construct_yaml_float>, 'tag:yaml.org,2002:int': <function SafeConstructor.construct_yaml_int>, 'tag:yaml.org,2002:map': <function SafeConstructor.construct_yaml_map>, 'tag:yaml.org,2002:null': <function SafeConstructor.construct_yaml_null>, 'tag:yaml.org,2002:omap': <function SafeConstructor.construct_yaml_omap>, 'tag:yaml.org,2002:pairs': <function SafeConstructor.construct_yaml_pairs>, 'tag:yaml.org,2002:seq': <function SafeConstructor.construct_yaml_seq>, 'tag:yaml.org,2002:set': <function SafeConstructor.construct_yaml_set>, 'tag:yaml.org,2002:str': <function SafeConstructor.construct_yaml_str>, 'tag:yaml.org,2002:timestamp': <function SafeConstructor.construct_yaml_timestamp>, None: <function SafeConstructor.construct_undefined>}¶
- capellambse.decl.apply(model, file)¶
Apply a declarative modelling file to the given model.
- Parameters:
model (MelodyModel) – The model to apply the instructions to.
file (IO[str] | str | PathLike[Any]) –
An open file-like object to read YAML instructions from, or a path to such a file. Files will be read with UTF-8 encoding.
The full format of these files is documented in the section about declarative modelling.
- Return type:
Notes
This function is not transactional: If an exception occurs during this function, the model will be left partially modified, with no reliable way to know how much of the YAML input has been consumed. It is therefore advised to reload or discard the model immediately in these cases, to avoid working with an inconsistent state.
Even though the YAML layout suggests linear execution from top to bottom, the actual order in which modifications are executed is implementation defined. This is necessary to support promises with
!promise
, but reorderings are still possible even if no promises are used in an input document.
- capellambse.decl.dump(instructions)¶
Dump an instruction stream to YAML.
capellambse.diagram_cache module¶
CLI for the diagram cache updating feature.
capellambse.helpers module¶
Miscellaneous utility functions used throughout the modules.
- class capellambse.helpers.EverythingContainer¶
-
A container that contains everything.
- capellambse.helpers.escape_linked_text(loader, attr_text)¶
Transform simple HTML with object links into
LinkedText
.This is the inverse operation of
unescape_linked_text()
.- Parameters:
loader (MelodyLoader)
attr_text (str)
- Return type:
- capellambse.helpers.extent_func(text, fonttype='OpenSans-Regular.ttf', size=12)¶
Calculate the display size of the given text.
- capellambse.helpers.flatten_html_string(text)¶
Convert an HTML-string to plain text.
- capellambse.helpers.get_text_extent(text, width=inf, fonttype='OpenSans-Regular.ttf', fontsize=12)¶
Calculate the bounding box size of
text
after line wrapping.- Parameters:
- Returns:
width – The width of the text after word wrapping (px).
height – The height of the text after word wrapping (px).
- Return type:
- capellambse.helpers.get_transformation(class_, pos, size)¶
Calculate transformation for class.
The Scaling factor .725, translation constants (6, 5) are arbitrarily chosen to fit. Currently only ChoicePseudoState is tranformed.
- capellambse.helpers.is_uuid_string(string)¶
Validate that
string
is a valid UUID.
- capellambse.helpers.load_font(fonttype, size)¶
- Parameters:
- Return type:
- capellambse.helpers.make_short_html(clsname, uuid, name='', value='')¶
- capellambse.helpers.normalize_pure_path(path, *, base='/')¶
Make a PurePosixPath relative to base and collapse
..
components.- Parameters:
path (str | PurePosixPath) – The input path to normalize.
base (str | PurePosixPath) – The base directory to which relative paths should be interpreted. Ignored if the input path is not relative.
- Returns:
The normalized path.
- Return type:
- capellambse.helpers.ntuples(num: int, iterable: Iterable[_T], *, pad: Literal[False] = False) Iterator[tuple[_T, ...]] ¶
- capellambse.helpers.ntuples(num: int, iterable: Iterable[_T], *, pad: Literal[True]) Iterator[tuple[_T | None, ...]]
Yield N items of
iterable
at once.- Parameters:
num – The number of items to yield at once.
iterable – An iterable.
pad – If the items in
iterable
are not evenly divisible byn
, pad the last yielded tuple withNone
s. If False, the last tuple will be discarded.
- Yields:
items – A
num
long tuple of items fromiterable
.
- capellambse.helpers.process_html_fragments(markup, node_callback)¶
Repair and modify HTML markup.
The original markup, which can be an HTML fragment (without a root element), is parsed and processed, and then reassembled into a Markup instance. If the original markup contained any errors or inconsistencies, these are repaired in the returned Markup instance.
- Parameters:
markup (str) – The markup string to modify.
node_callback (Callable[[_Element], None]) –
A callback function to process each node in the parsed markup. The function should accept a single
lxml.etree._Element
as argument; its return value is ignored.Note that, since the markup is parsed as fragments, more than the first element passed to the callback may have no parent.
The callback will not be invoked for leading text, if there is any, and thus it has no ability to influence it.
- Returns:
The processed markup.
- Return type:
- capellambse.helpers.relpath_pure(path, start)¶
Calculate the relative path between two pure paths.
Unlike
pathlib.PurePath.relative_to()
, this method can cope withpath
not being a subpath ofstart
. And unlike theos.path.relpath()
function, it does not involve any filesystem access.- Parameters:
path (PurePosixPath)
start (PurePosixPath)
- Return type:
- capellambse.helpers.repair_html(markup)¶
Try to repair broken HTML markup to prevent parse errors.
- Parameters:
markup (str) – The markup to try and repair.
- Returns:
The repaired markup.
- Return type:
- capellambse.helpers.replace_hlinks(markup, model, make_href, *, broken_link_css='color: red; text-decoration: line-through;')¶
Replace hlink:// links with arbitrary other links.
- Parameters:
markup (str) – The markup to process.
model (MelodyModel) – The model to use for resolving UUIDs.
make_href (Callable[[GenericElement], str | None]) – A function that maps objects to URLs. This function is called once for each link (possibly multiple times for the same object), and must return a URL to be inserted in place of the original
hlink://...
URL.broken_link_css (str) – Broken links (links to objects that have been deleted, and links where the
make_href
callback returned None or an empty string) are indicated by a<span>
element with this CSS style applied to it.
- Return type:
- capellambse.helpers.resolve_namespace(tag)¶
Resolve a ‘:’-delimited symbolic namespace to its canonical form.
- capellambse.helpers.split_links(links)¶
Split a string containing intra- and inter-fragment links.
Intra-fragment links are simply “#UUID”, whereas inter-fragment links look like “xtype fragment#UUID”. Multiple such links are space-separated in a single long string to form a list. This function splits such a string back into its individual components (each being either an intra- or inter-fragment link), and yields them.
- capellambse.helpers.ssvparse(string, cast, *, parens=('', ''), sep=',', num=0)¶
Parse a string of
sep
-separated values wrapped inparens
.- Parameters:
string (str) – The input string.
cast (Callable[[str], _T]) – A type to cast the values into.
parens (Sequence[str]) – The parentheses that must exist around the input. Either a two-character string or a 2-tuple of strings.
sep (str) – The separator between values.
num (int) – If non-zero, only accept exactly this many values.
- Returns:
A list of values cast into the given type.
- Return type:
list[_T]
- Raises:
ValueError – If the parentheses are missing around the input string, or if the expected number of values doesn’t match the actual number.
- capellambse.helpers.unescape_linked_text(loader, attr_text)¶
Transform the
linkedText
into regular HTML.- Parameters:
loader (MelodyLoader)
attr_text (str | None)
- Return type:
- capellambse.helpers.word_wrap(text, width)¶
Perform word wrapping for proportional fonts.
Whitespace at the beginning of input lines is preserved, but other whitespace is collapsed to single spaces. Words are kept as a whole, possibly leading to exceeding width bound.
- capellambse.helpers.xpath_fetch_unique(xpath: str | XPath, tree: _Element, elm_name: str, elm_uid: str | None = None, *, optional: Literal[False] = False) _Element ¶
- capellambse.helpers.xpath_fetch_unique(xpath: str | XPath, tree: _Element, elm_name: str, elm_uid: str | None = None, *, optional: Literal[True]) _Element | None
Fetch an XPath result from the tree, ensuring that it’s unique.
- Parameters:
xpath – The
lxml.etree.XPath
object to apply, or an XPath expression as str.tree – The (sub-)tree to which the XPath will be applied.
elm_name – A human-readable element name for error messages.
elm_uid – UID of the element which triggered this lookup. Will be included in the error message if an error occured.
optional – True to return None in case the element is not found. Otherwise a ValueError will be raised.
- Returns:
The Element found by given
xpath
.- Return type:
lxml.etree._Element | None
- Raises:
ValueError – If more than one element was found matching the
xpath
, or ifoptional
isFalse
and no matching element was found.
- capellambse.helpers.xtype_of(elem)¶
Return the
xsi:type
of the element.If the element has an
xsi:type
attribute, its value is returned.If the element does not have an
xsi:type
, this function resolves the tag’s namespace to the symbolic name and reconstructs the type with thenamespace:tag
template.- Parameters:
elem (_Element) – The
lxml.etree._Element
object to return thexsi:type
for.- Raises:
capellambse.UnsupportedPluginError – If the plugin is unknown and therefore not supported.
capellambse.UnsupportedPluginVersionError – If the plugin’s version is not supported.
- Returns:
The
xsi:type
string of the provided element orNone
if the type could not be determined.- Return type:
str | None