summaryrefslogtreecommitdiffstats
path: root/rtemsspec/items.py
diff options
context:
space:
mode:
Diffstat (limited to 'rtemsspec/items.py')
-rw-r--r--rtemsspec/items.py64
1 files changed, 45 insertions, 19 deletions
diff --git a/rtemsspec/items.py b/rtemsspec/items.py
index 32a9eeaa..3a2d5e34 100644
--- a/rtemsspec/items.py
+++ b/rtemsspec/items.py
@@ -266,26 +266,30 @@ class Item:
"""
return self._cache[self.to_abs_uid(abs_or_rel_uid)]
- def links_to_parents(self) -> Iterator[Link]:
- """ Yields the links to the parents of this items. """
- yield from self._links_to_parents
-
- def parents(
+ def links_to_parents(
self,
role: Optional[Union[str,
- Iterable[str]]] = None) -> Iterator["Item"]:
- """ Yields the parents of this items. """
+ Iterable[str]]] = None) -> Iterator[Link]:
+ """ Yields the links to the parents of this items. """
if role is None:
for link in self._links_to_parents:
- yield link.item
+ yield link
elif isinstance(role, str):
for link in self._links_to_parents:
if link.role == role:
- yield link.item
+ yield link
else:
for link in self._links_to_parents:
if link.role in role:
- yield link.item
+ yield link
+
+ def parents(
+ self,
+ role: Optional[Union[str,
+ Iterable[str]]] = None) -> Iterator["Item"]:
+ """ Yields the parents of this items. """
+ for link in self.links_to_parents(role):
+ yield link.item
def parent(self,
role: Optional[Union[str, Iterable[str]]] = None,
@@ -296,26 +300,39 @@ class Item:
return item
raise IndexError
- def links_to_children(self) -> Iterator[Link]:
- """ Yields the links to the children of this items. """
- yield from self._links_to_children
+ def parent_link(self,
+ role: Optional[Union[str, Iterable[str]]] = None,
+ index: Optional[int] = 0) -> Link:
+ """ Returns the parent link with the specified role and index. """
+ for link_index, link in enumerate(self.links_to_parents(role)):
+ if link_index == index:
+ return link
+ raise IndexError
- def children(
+ def links_to_children(
self,
role: Optional[Union[str,
- Iterable[str]]] = None) -> Iterator["Item"]:
- """ Yields the children of this items. """
+ Iterable[str]]] = None) -> Iterator[Link]:
+ """ Yields the links to the children of this items. """
if role is None:
for link in self._links_to_children:
- yield link.item
+ yield link
elif isinstance(role, str):
for link in self._links_to_children:
if link.role == role:
- yield link.item
+ yield link
else:
for link in self._links_to_children:
if link.role in role:
- yield link.item
+ yield link
+
+ def children(
+ self,
+ role: Optional[Union[str,
+ Iterable[str]]] = None) -> Iterator["Item"]:
+ """ Yields the children of this items. """
+ for link in self.links_to_children(role):
+ yield link.item
def child(self,
role: Optional[Union[str, Iterable[str]]] = None,
@@ -326,6 +343,15 @@ class Item:
return item
raise IndexError
+ def child_link(self,
+ role: Optional[Union[str, Iterable[str]]] = None,
+ index: Optional[int] = 0) -> Link:
+ """ Returns the child link with the specified role and index. """
+ for link_index, link in enumerate(self.links_to_children(role)):
+ if link_index == index:
+ return link
+ raise IndexError
+
def init_parents(self, item_cache: "ItemCache") -> None:
""" Initializes the list of links to parents of this items. """
for data in self._data["links"]: