diff options
-rwxr-xr-x | pyfingerd/cli.py | 4 | ||||
-rwxr-xr-x | pyfingerd/core.py | 48 | ||||
-rwxr-xr-x | pyfingerd/fiction.py | 23 |
3 files changed, 37 insertions, 38 deletions
diff --git a/pyfingerd/cli.py b/pyfingerd/cli.py index 8592314..659892c 100755 --- a/pyfingerd/cli.py +++ b/pyfingerd/cli.py @@ -99,12 +99,12 @@ def cli(binds, hostname, type_, scenario, scenario_start, log_level): fic = _FingerScenario.load(scenario) iface = _FingerScenarioInterface(fic, scenario_start) except (FileNotFoundError, PermissionError) as exc: - _logger.error(str(exc)) + _logger.error('%s', exc) return 1 except ValueError as exc: exc = str(exc) _logger.error('Error loading the scenario:') - _logger.error(f'{exc[0].upper()}{exc[1:]}.') + _logger.error('%s%s.', exc[0].upper(), exc[1:]) return 1 elif type_ != 'dummy': print( diff --git a/pyfingerd/core.py b/pyfingerd/core.py index 2fbd044..0f40e51 100755 --- a/pyfingerd/core.py +++ b/pyfingerd/core.py @@ -894,7 +894,8 @@ class FingerServer: line = await inp.readline() except ConnectionResetError: _error_logger.info( - f'{src} submitted no query. (possible scan)', + '%s submitted no query. (possible scan)', + src, ) outp.close() return @@ -906,7 +907,8 @@ class FingerServer: query = _FingerQuery(line) except _MalformedQueryError as e: _error_logger.info( - f'{src} made a bad request: {e.msg} in {e.query!r}.', + '%s made a bad request: %s in %r.', + src, e.msg, e.query, ) ans = self.formatter.format_query_error( self.hostname, line, @@ -915,13 +917,15 @@ class FingerServer: if query.host is not None: if query.username: _access_logger.info( - f'{src} requested transmitting user query for ' - + f'{query.username!r} at {query.host!r}.', + '%s requested transmitting user query for ' + + '%r at %r.', + src, query.username, query.host, ) else: _access_logger.info( - f'{src} requested transmitting user query ' - + f'to {query.host!r}.', + '%s requested transmitting user query ' + + 'to %r.', + src, query.host, ) ans = self.interface.transmit_query( @@ -933,22 +937,20 @@ class FingerServer: query.username, None, ) _access_logger.info( - f'{src} requested user {query.username!r}: found ' - + ( + '%s requested user %r: found %s.', + src, query.username, ( {0: 'no user', 1: '1 user'} .get(len(users), f'{len(users)} users') - ) - + '.', + ), ) else: users = self.interface.search_users(None, True) _access_logger.info( - f'{src} requested connected users: found ' - + ( + '%s requested connection users: found %s.', + src, ( {0: 'no user', 1: '1 user'} .get(len(users), f'{len(users)} users') - ) - + '.', + ), ) if query.username or query.verbose: @@ -993,31 +995,27 @@ class FingerServer: if name == 'EADDRINUSE': _logger.error( - f'Could not bind to [{host}]:{port}: ' - + 'address already in use.', + 'Could not bind to [%s]:%d: address already in use.', + host, port, ) return elif name == 'EACCES': _logger.error( - f'Could not bind to [{host}]:{port}: ' - + f'port {port} privileged port and process ' - + 'is unprivileged.', + 'Could not bind to [%s]:%d: port %d is a privileged ' + + 'port and process is unprivileged.', + host, port, port, ) else: raise else: - _logger.info( - f'Starting pyfingerd on [{host}]:{port}.', - ) + _logger.info('Starting pyfingerd on [%s]:%d.', host, port) try: await server.serve_forever() except _asyncio.CancelledError: pass - _logger.info( - f'Stopping pyfingerd on [{host}]:{port}.', - ) + _logger.info('Stopping pyfingerd on [%s]:%d', host, port) async def cron_call(func, spec): """Call a function periodically using a cron specification.""" diff --git a/pyfingerd/fiction.py b/pyfingerd/fiction.py index 73b910d..8e70681 100755 --- a/pyfingerd/fiction.py +++ b/pyfingerd/fiction.py @@ -896,7 +896,7 @@ class FingerScenario: end_type = None end_time = None - _logger.debug(f'Loading scenario from {path!r}.') + _logger.debug('Loading scenario from %r.', path) # Load the required modules. if _toml is None: @@ -904,7 +904,8 @@ class FingerScenario: import toml except ModuleNotFoundError: raise ModuleNotFoundError( - "'toml' module required") from None + "'toml' module required", + ) from None _toml = toml del toml @@ -935,7 +936,8 @@ class FingerScenario: 'interrupt': cls.EndingType.FREEZE, 'freeze': cls.EndingType.FREEZE, 'stop': cls.EndingType.STOP, - 'repeat': cls.EndingType.REPEAT}[typ] + 'repeat': cls.EndingType.REPEAT, + }[typ] end_time = time continue @@ -985,9 +987,7 @@ class FingerScenario: ) elif typ == 'delete': # User deletion. - action = FingerUserDeletionAction( - login=data['login'], - ) + action = FingerUserDeletionAction(login=data['login']) elif typ == 'login': # User login. action = FingerUserLoginAction( @@ -1023,7 +1023,8 @@ class FingerScenario: # Sort and check the actions. _logger.debug( - f'Loaded {len(actions)} action{("", "s")[len(actions) >= 2]}.', + 'Loaded %d action%s.', + len(actions), 's'[:len(actions) >= 2], ) if end_type is None: @@ -1173,7 +1174,7 @@ class FingerScenarioInterface(FingerFictionInterface): self._lastdelta = None _logger.debug('Repeat ending has been reached.') - _logger.debug(f'Looping from {start.isoformat()}.') + _logger.debug('Looping from %s.', start.isoformat()) # We're within the duration of the fiction, so we just use the # offset from the start. @@ -1186,11 +1187,11 @@ class FingerScenarioInterface(FingerFictionInterface): actions = list(actions) if actions: _logger.debug( - f'Applying {len(actions)} ' - + f'action{("", "s")[len(actions) >= 2]}:', + 'Applying %d action%s:', + len(actions), 's'[:len(actions) >= 2], ) for time, action in actions: - _logger.debug(f' at {_format_delta(time)}: {action!r}') + _logger.debug(' at %s: %r', _format_delta(time), action) for time, action in actions: self.apply(action, start + time) |