diff options
author | John Estabrook <jestabro@vyos.io> | 2023-06-02 23:29:56 -0500 |
---|---|---|
committer | John Estabrook <jestabro@vyos.io> | 2023-06-22 20:12:12 -0500 |
commit | d57b7d327cef20dc607550bda1c5632c3d24a719 (patch) | |
tree | 0c1829ca8c5a2748ed439b554d3beb01832f496c | |
parent | f2f6b963b755ca5da3321e84738bfec1d08fb1ea (diff) | |
download | vyos-1x-d57b7d327cef20dc607550bda1c5632c3d24a719.tar.gz vyos-1x-d57b7d327cef20dc607550bda1c5632c3d24a719.zip |
config: T5228: use local _dict_merge to avoid circular import
-rw-r--r-- | python/vyos/xml_ref/definition.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/python/vyos/xml_ref/definition.py b/python/vyos/xml_ref/definition.py index 970dd915f..92d069f05 100644 --- a/python/vyos/xml_ref/definition.py +++ b/python/vyos/xml_ref/definition.py @@ -14,7 +14,6 @@ # along with this library. If not, see <http://www.gnu.org/licenses/>. from typing import Optional, Union, Any -from vyos.configdict import dict_merge class Xml: def __init__(self): @@ -186,6 +185,20 @@ class Xml: return False return True + # use local copy of function in module configdict, to avoid circular + # import + def _dict_merge(self, source, destination): + from copy import deepcopy + tmp = deepcopy(destination) + + for key, value in source.items(): + if key not in tmp: + tmp[key] = value + elif isinstance(source[key], dict): + tmp[key] = self._dict_merge(source[key], tmp[key]) + + return tmp + def _relative_defaults(self, rpath: list, conf: dict, recursive=False) -> dict: res: dict = {} res = self.get_defaults(rpath, recursive=recursive, @@ -234,5 +247,5 @@ class Xml: """ d = self.relative_defaults(path, conf, get_first_key=get_first_key, recursive=recursive) - d = dict_merge(d, conf) + d = self._dict_merge(d, conf) return d |