summaryrefslogtreecommitdiff
path: root/python/vyos/util.py
diff options
context:
space:
mode:
Diffstat (limited to 'python/vyos/util.py')
-rw-r--r--python/vyos/util.py12
1 files changed, 9 insertions, 3 deletions
diff --git a/python/vyos/util.py b/python/vyos/util.py
index 6a828c0ac..0593184cc 100644
--- a/python/vyos/util.py
+++ b/python/vyos/util.py
@@ -348,9 +348,11 @@ def colon_separated_to_dict(data_string, uniquekeys=False):
l = l.strip()
if l:
match = re.match(key_value_re, l)
- if match:
+ if match and (len(match.groups()) == 2):
key = match.groups()[0].strip()
value = match.groups()[1].strip()
+ else:
+ raise ValueError(f"""Line "{l}" could not be parsed a colon-separated pair """, l)
if key in data.keys():
if uniquekeys:
raise ValueError("Data string has duplicate keys: {0}".format(key))
@@ -486,7 +488,7 @@ def is_listen_port_bind_service(port: int, service: str) -> bool:
Example:
% is_listen_port_bind_service(443, 'nginx')
True
- % is_listen_port_bind_service(443, 'ocservr-main')
+ % is_listen_port_bind_service(443, 'ocserv-main')
False
"""
from psutil import net_connections as connections
@@ -872,12 +874,16 @@ def convert_data(data):
Returns:
str | list | dict: converted data
"""
+ from base64 import b64encode
from collections import OrderedDict
if isinstance(data, str):
return data
if isinstance(data, bytes):
- return data.decode()
+ try:
+ return data.decode()
+ except UnicodeDecodeError:
+ return b64encode(data).decode()
if isinstance(data, list):
list_tmp = []
for item in data: