From ac9d5f61e7e9151f7518c26db192dd6d0bf56591 Mon Sep 17 00:00:00 2001 From: sebres Date: Wed, 24 Jan 2018 15:47:05 +0100 Subject: [PATCH] rewrite keywords reserved in python 3.7 (`async` -> `nonsync`) --- fail2ban/client/fail2banclient.py | 6 +++--- fail2ban/client/fail2banserver.py | 23 +++++++++++++---------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/fail2ban/client/fail2banclient.py b/fail2ban/client/fail2banclient.py index 0a1ae4f1..13ebcdef 100755 --- a/fail2ban/client/fail2banclient.py +++ b/fail2ban/client/fail2banclient.py @@ -228,9 +228,9 @@ class Fail2banClient(Fail2banCmdLine, Thread): return True ## - def configureServer(self, async=True, phase=None): - # if asynchron start this operation in the new thread: - if async: + def configureServer(self, nonsync=True, phase=None): + # if asynchronous start this operation in the new thread: + if nonsync: th = Thread(target=Fail2banClient.configureServer, args=(self, False, phase)) th.daemon = True return th.start() diff --git a/fail2ban/client/fail2banserver.py b/fail2ban/client/fail2banserver.py index 6c57fbf8..afe36cf4 100644 --- a/fail2ban/client/fail2banserver.py +++ b/fail2ban/client/fail2banserver.py @@ -164,21 +164,24 @@ class Fail2banServer(Fail2banCmdLine): cli = self._Fail2banClient() return cli.start(argv) - # Start the server: - from ..server.utils import Utils - # background = True, if should be new process running in background, otherwise start in foreground - # process will be forked in daemonize, inside of Server module. - # async = True, if started from client, should... + # Start the server, corresponding options: + # background = True, if should be new process running in background, otherwise start in + # foreground process will be forked in daemonize, inside of Server module. + # nonsync = True, normally internal call only, if started from client, so configures + # the server via asynchronous thread. background = self._conf["background"] - async = self._conf.get("async", False) + nonsync = self._conf.get("async", False) + # If was started not from the client: - if not async: + if not nonsync: + # Load requirements on demand (we need utils only when asynchronous handling): + from ..server.utils import Utils # Start new thread with client to read configuration and # transfer it to the server: cli = self._Fail2banClient() phase = dict() logSys.debug('Configure via async client thread') - cli.configureServer(async=True, phase=phase) + cli.configureServer(phase=phase) # wait, do not continue if configuration is not 100% valid: Utils.wait_for(lambda: phase.get('ready', None) is not None, self._conf["timeout"], 0.001) logSys.log(5, ' server phase %s', phase) @@ -195,7 +198,7 @@ class Fail2banServer(Fail2banCmdLine): pid = os.getpid() server = Fail2banServer.startServerDirect(self._conf, background) # notify waiting thread server ready resp. done (background execution, error case, etc): - if not async: + if not nonsync: _server_ready() # If forked - just exit other processes if pid != os.getpid(): # pragma: no cover @@ -204,7 +207,7 @@ class Fail2banServer(Fail2banCmdLine): cli._server = server # wait for client answer "done": - if not async and cli: + if not nonsync and cli: Utils.wait_for(lambda: phase.get('done', None) is not None, self._conf["timeout"], 0.001) if not phase.get('done', False): if server: # pragma: no cover