def find_all(self, xpath: str) -> Iterator["DNode"]: node_set = lib.lyd_find_path(self.cdata, str2c(xpath)) if not node_set: raise self.context.error("cannot find path") try: for i in range(node_set.number): yield DNode.new(self.context, node_set.d[i]) finally: lib.ly_set_free(node_set)
def find_all(self, xpath): node_set = lib.lyd_find_path(self._node, str2c(xpath)) if not node_set: raise self.context.error('cannot find path') try: for i in range(node_set.number): yield DNode.new(self.context, node_set.d[i]) finally: lib.ly_set_free(node_set)
def find_path(self, path): if self._ctx is None: raise RuntimeError('context already destroyed') node_set = lib.ly_ctx_find_path(self._ctx, str2c(path)) if not node_set: raise self.error('cannot find path') try: for i in range(node_set.number): yield SNode.new(self, node_set.set.s[i]) finally: lib.ly_set_free(node_set)
def find_path(self, path: str) -> Iterator[SNode]: if self.cdata is None: raise RuntimeError("context already destroyed") node_set = lib.ly_ctx_find_path(self.cdata, str2c(path)) if not node_set: raise self.error("cannot find path") try: for i in range(node_set.number): yield SNode.new(self, node_set.set.s[i]) finally: lib.ly_set_free(node_set)
def create_data_path( self, path: str, parent: Optional[DNode] = None, value: Any = None, update: bool = True, no_parent_ret: bool = True, rpc_output: bool = False, force_return_value: bool = True, ) -> Optional[DNode]: if self.cdata is None: raise RuntimeError("context already destroyed") lib.lypy_set_errno(0) if value is not None: if isinstance(value, bool): value = str(value).lower() elif not isinstance(value, str): value = str(value) flags = path_flags(update=update, no_parent_ret=no_parent_ret, rpc_output=rpc_output) dnode = lib.lyd_new_path( parent.cdata if parent else ffi.NULL, self.cdata, str2c(path), str2c(value), 0, flags, ) if lib.lypy_get_errno() != lib.LY_SUCCESS: if lib.ly_vecode(self.cdata) != lib.LYVE_PATH_EXISTS: raise self.error("cannot create data path: %s", path) lib.ly_err_clean(self.cdata, ffi.NULL) lib.lypy_set_errno(0) if not dnode and not force_return_value: return None if not dnode and parent: # This can happen when path points to an already created leaf and # its value does not change. # In that case, lookup the existing leaf and return it. node_set = lib.lyd_find_path(parent.cdata, str2c(path)) try: if not node_set or not node_set.number: raise self.error("cannot find path: %s", path) dnode = node_set.set.s[0] finally: lib.ly_set_free(node_set) if not dnode: raise self.error("cannot find created path") return DNode.new(self, dnode)