diff options
author | John Estabrook <jestabro@vyos.io> | 2020-07-22 19:36:05 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-22 19:36:05 -0500 |
commit | 2c33099f8be42f8a1cb89d8b925377507c34c516 (patch) | |
tree | 5780fae80500ff6be5bc5503487d4fd5f2a82e43 /python/vyos/xml/definition.py | |
parent | da65aa2290e54f47dcc9c527723557fdbe2cb892 (diff) | |
parent | faaad2e029fd3520b62983dd78c7692434138360 (diff) | |
download | vyos-1x-2c33099f8be42f8a1cb89d8b925377507c34c516.tar.gz vyos-1x-2c33099f8be42f8a1cb89d8b925377507c34c516.zip |
Merge pull request #481 from thomas-mangin/T2582
xml: T2582: use xml for is_tag and is_leaf
Diffstat (limited to 'python/vyos/xml/definition.py')
-rw-r--r-- | python/vyos/xml/definition.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/python/vyos/xml/definition.py b/python/vyos/xml/definition.py index b0339b228..098e64f7e 100644 --- a/python/vyos/xml/definition.py +++ b/python/vyos/xml/definition.py @@ -126,10 +126,12 @@ class XML(dict): elif word: if data_node != kw.plainNode or len(passed) == 1: self.options = [_ for _ in self.tree if _.startswith(word)] + self.options.sort() else: self.options = [] else: self.options = named_options + self.options.sort() self.plain = not is_dataNode @@ -143,6 +145,7 @@ class XML(dict): self.word = '' if self.tree.get(kw.node,'') not in (kw.tagNode, kw.leafNode): self.options = [_ for _ in self.tree if not kw.found(_)] + self.options.sort() def checks(self, cmd): # as we move thought the named node twice @@ -300,16 +303,28 @@ class XML(dict): return tree def _get(self, lpath, tag, with_tag=True): - return self._tree(lpath + [tag], with_tag) + tree = self._tree(lpath, with_tag) + if tree is None: + return None + return tree.get(tag, None) def is_multi(self, lpath, with_tag=True): - return self._get(lpath, kw.multi, with_tag) is True + tree = self._get(lpath, kw.multi, with_tag) + if tree is None: + return None + return tree is True def is_tag(self, lpath, with_tag=True): - return self._get(lpath, kw.node, with_tag) == kw.tagNode + tree = self._get(lpath, kw.node, with_tag) + if tree is None: + return None + return tree == kw.tagNode def is_leaf(self, lpath, with_tag=True): - return self._get(lpath, kw.node, with_tag) == kw.leafNode + tree = self._get(lpath, kw.node, with_tag) + if tree is None: + return None + return tree == kw.leafNode def exists(self, lpath, with_tag=True): return self._get(lpath, kw.node, with_tag) is not None |