Refs¶
In the bundle XML file the ref attribute can be used to refer to another element in the same bundle.
ref is supported by the <file>
, <checklet>
and <option>
nodes.
The element is referred to by its id attribute, and must be defined at a higher level in the XML file. When using the ref attribute, the node should not have any other attributes or child elements.
When accessing the elements using the API provided by this package, the ref attribute is automatically resolved to the referred element.
Note
ref is not yet implemented for creating new bundles, only when reading existing bundles. This is tracked in issue #2.
API¶
- momotor.bundles.elements.refs.resolve_ref(tag_name, node, groups)¶
Resolve reference. Used internally by the classes implementing referable nodes, so there should be no need to call this method directly.
- Parameters:
tag_name (
str
) – tag name of referenced nodenode (
TypeVar
(CT
, bound=Union
[FileComplexType
,OptionComplexType
,CheckletComplexType
])) – node to resolve reference of (should have aref
attribute)groups (
Iterable
[Iterable
[object
]]) – parent groups to search the reference in
- Return type:
tuple
[object
|None
,TypeVar
(CT
, bound=Union
[FileComplexType
,OptionComplexType
,CheckletComplexType
])]- Returns:
a tuple (parent, node). parent can be
None
, in that case, ref attribute wasNone
and provided node is returned. Otherwise, returns the resolved reference.- Raises:
InvalidRefError
when reference cannot be resolved