def defnode(self, name, expr, value): """Define a variable 'name' whose value is the result of evaluating 'expr', which must not be None and evaluate to a nodeset. If a variable 'name' already exists, its name will be replaced with the result of evaluating 'expr'. If 'expr' evaluates to an empty nodeset, a node is created, equivalent to calling set(expr, value) and 'name' will be the nodeset containing that single node.""" # Sanity checks if type(name) != str: raise TypeError("name MUST be a string!") if type(expr) != str: raise TypeError("expr MUST be a string!") if type(value) != str: raise TypeError("value MUST be a string!") if not self.__handle: raise RuntimeError("The Augeas object has already been closed!") # Call the function ret = lib.aug_defnode(self.__handle, enc(name), enc(expr), enc(value), ffi.NULL) if ret < 0: raise ValueError("Unable to register node!") return ret
def defnode(self, name, expr, value): """ Define a variable `name` whose value is the result of evaluating `expr`, which must not be :py:obj:`None` and evaluate to a nodeset. If a variable `name` already exists, its name will be replaced with the result of evaluating `expr`. If `expr` evaluates to an empty nodeset, a node is created, equivalent to calling ``set(expr, value)`` and `name` will be the nodeset containing that single node. """ # Sanity checks if type(name) != str: raise TypeError("name MUST be a string!") if type(expr) != str: raise TypeError("expr MUST be a string!") if type(value) != str: raise TypeError("value MUST be a string!") if not self.__handle: raise RuntimeError("The Augeas object has already been closed!") # Call the function ret = lib.aug_defnode( self.__handle, enc(name), enc(expr), enc(value), ffi.NULL) if ret < 0: self._raise_error(AugeasValueError, "Augeas.defnode() failed") return ret