Skip to content

Commit

Permalink
Make Python API compatible with Python 2 & 3
Browse files Browse the repository at this point in the history
Re-factor the Python 2 Livestatus library to work under both 2/3:

* Replace some py2-only idioms and fix some errors like trying to access
  `.keys()` on a list.

* Let all literal strings be unicode on both py2/3
  (`from __future__ import unicode_literals`). This way, the modules
  code internally works with unicode stings (`unicode` on py2, `str` on
  py3) and converts to byte strings when writing to socket.

* API methods take either unicode strings or byte (`str` on py2, `bytes`
  on py3) as input.

Signed-off-by: Aksel Sjögren <asjogren@itrsgroup.com>
  • Loading branch information
sjoegren committed Dec 3, 2021
1 parent 15d9315 commit 279e618
Show file tree
Hide file tree
Showing 2 changed files with 102 additions and 67 deletions.
27 changes: 19 additions & 8 deletions api/python/__init__.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
from livestatus import SingleSiteConnection, MultiSiteConnection, MKLivestatusException, MKLivestatusSocketError, MKLivestatusSocketClosed, MKLivestatusQueryError, MKLivestatusNotFoundError
from __future__ import absolute_import
from .livestatus import (
SingleSiteConnection,
MultiSiteConnection,
MKLivestatusException,
MKLivestatusSocketError,
MKLivestatusSocketClosed,
MKLivestatusQueryError,
MKLivestatusNotFoundError,
)

__all__ = [
'SingleSiteConnection',
'MultiSiteConnection',
'MKLivestatusException',
'MKLivestatusSocketError',
'MKLivestatusSocketClosed',
'MKLivestatusQueryError',
'MKLivestatusNotFoundError']
"SingleSiteConnection",
"MultiSiteConnection",
"MKLivestatusException",
"MKLivestatusSocketError",
"MKLivestatusSocketClosed",
"MKLivestatusQueryError",
"MKLivestatusNotFoundError",
]
Loading

0 comments on commit 279e618

Please sign in to comment.