def _ls(self, client: CommandClient, object_type: str | None) -> tuple[list[str], list[str]]: if object_type is not None: allow_root, items = client.items(object_type) str_items = [str(i) for i in items] if allow_root: children = client.navigate(object_type, None).children else: children = [] return children, str_items else: return client.children, []
def _find_node( self, src: CommandClient, *paths: str) -> Tuple[Optional[CommandClient], Optional[str]]: """Find an object in the command graph Return the object in the command graph at the specified path relative to the given node. """ if len(paths) == 0: return src, None path, *next_path = paths if path == "..": return self._find_node(src.parent or src, *next_path) if path not in src.children: return None, None if len(next_path) == 0: return src, path item, *maybe_next_path = next_path allow_root, items = src.items(path) for transformation in [str, int]: try: transformed_item = transformation(item) except ValueError: continue if transformed_item in items: next_node = src.navigate(path, transformed_item) return self._find_node(next_node, *maybe_next_path) if not allow_root: return None, None next_node = src.navigate(path, None) return self._find_node(next_node, *next_path)