diff options
author | Daniel Salzman <daniel.salzman@nic.cz> | 2022-05-17 09:40:38 +0200 |
---|---|---|
committer | Daniel Salzman <daniel.salzman@nic.cz> | 2022-05-17 11:07:31 +0200 |
commit | bbd532d87fd0237b35f2724c9ce5e19565d43e5a (patch) | |
tree | 8a01fe59aceeef7c69d80889bb6153aae06a1276 /python | |
parent | python/libknot: raise various control exceptions to better distinguish the ex... (diff) | |
download | knot-bbd532d87fd0237b35f2724c9ce5e19565d43e5a.tar.xz knot-bbd532d87fd0237b35f2724c9ce5e19565d43e5a.zip |
python/libknot: remove some compatibility for Python2, improve function output
Diffstat (limited to 'python')
-rw-r--r-- | python/libknot/control.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/python/libknot/control.py b/python/libknot/control.py index f6259f880..44aa51687 100644 --- a/python/libknot/control.py +++ b/python/libknot/control.py @@ -57,7 +57,7 @@ class KnotCtlData(object): if self.data[idx]: if string: string += ", " - string += "%s = %s" % (idx.name, self.data[idx]) + string += "%s = '%s'" % (idx.name, self.data[idx].decode()) return string @@ -65,9 +65,7 @@ class KnotCtlData(object): """Data unit item getter.""" value = self.data[index] - if not value: - value = str() - return value if isinstance(value, str) else value.decode() + return value.decode() if value else str() def __setitem__(self, index: KnotCtlDataIdx, value: str) -> None: """Data unit item setter.""" @@ -165,7 +163,7 @@ class KnotCtl(object): ret = KnotCtl.CONNECT(self.obj, path.encode()) if ret != 0: err = libknot.Knot.STRERROR(ret) - raise KnotCtlErrorConnect(err if isinstance(err, str) else err.decode()) + raise KnotCtlErrorConnect(err.decode()) def close(self) -> None: """Disconnects from the current control socket.""" @@ -179,7 +177,7 @@ class KnotCtl(object): data.data if data else ctypes.c_char_p()) if ret != 0: err = libknot.Knot.STRERROR(ret) - raise KnotCtlErrorSend(err if isinstance(err, str) else err.decode()) + raise KnotCtlErrorSend(err.decode()) def receive(self, data: KnotCtlData = None) -> KnotCtlType: """Receives a data unit from the connected control socket.""" @@ -189,7 +187,7 @@ class KnotCtl(object): data.data if data else ctypes.c_char_p()) if ret != 0: err = libknot.Knot.STRERROR(ret) - raise KnotCtlErrorReceive(err if isinstance(err, str) else err.decode()) + raise KnotCtlErrorReceive(err.decode()) return KnotCtlType(data_type.value) def send_block(self, cmd: str, section: str = None, item: str = None, |