From ca203f339f392ec7590cd3fcf5ac7847ea3c1f28 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Fri, 11 Sep 2020 14:32:22 -0500 Subject: util: Add accessory functions for editing config --- ncserver/base/util.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) (limited to 'ncserver/base') diff --git a/ncserver/base/util.py b/ncserver/base/util.py index 3df076c..f69c65b 100644 --- a/ncserver/base/util.py +++ b/ncserver/base/util.py @@ -11,8 +11,35 @@ SPDX-License-Identifier: NCSA """ -def _(the_string): +from netconf import error + + +def _(the_string: str) -> str: """Translate a user-facing string. Currently not implemented, but allows us to implement translation later.""" return the_string + + +def ensure_leaf(rpc, node): + """Ensure that the node is a leaf (contains no child nodes).""" + if len(node) > 0: + raise error.UnknownElementAppError(rpc, node[0]) + + +def node_operation(node, def_op='merge') -> str: + """Determine the operation desired for an XML node. + + :param node: + The node. + + :param str def_op: + The default operation if none is specified. Defaults to 'merge'. + + :returns str: + The operation desired. + """ + + nc10 = '{urn:ietf:params:xml:ns:netconf:base:1.0}operation' + nc11 = '{urn:ietf:params:xml:ns:netconf:base:1.1}operation' + return node.attrib.get(nc11, node.attrib.get(nc10, def_op)) -- cgit v1.2.3-60-g2f50