From 8bf1b924055cac270d931666ad2b7fdb82fdebac Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Thu, 24 Oct 2019 11:32:05 +0200 Subject: [vyos.config] T1764: support both string and list arguments in config functions. --- python/vyos/config.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'python/vyos') diff --git a/python/vyos/config.py b/python/vyos/config.py index 2232d900c..3a340b2da 100644 --- a/python/vyos/config.py +++ b/python/vyos/config.py @@ -126,7 +126,12 @@ class Config(object): # splitting at whitespace is reasonably safe. # It may cause problems with exists() when it's used for checking values, # since values may contain whitespace. - path = re.split(r'\s*', path) + if isinstance(path, str): + path = re.split(r'\s*', path) + elif isinstance(path, list): + pass + else: + raise TypeError("Path must be a whitespace-separated string or a list") return (self._level + path) def _run(self, cmd): @@ -155,7 +160,12 @@ class Config(object): # Make sure there's always a space between default path (level) # and path supplied as method argument # XXX: for small strings in-place concatenation is not a problem - self._level = re.split(r'\s*', path) + if isinstance(path, str): + self._level = re.split(r'\s*', path) + elif isinstance(path, list): + self._level = path + else: + raise TypeError("Level path must be either a whitespace-separated string or a list") def get_level(self): """ -- cgit v1.2.3