diff options
author | Devaev Maxim <[email protected]> | 2019-06-28 18:59:36 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-06-28 18:59:36 +0300 |
commit | ef3c62a7af520673154233e2d3c89492ffec3195 (patch) | |
tree | 2b78c5918143eff8ef2c89484ac99fc6b7588438 /kvmd/apps | |
parent | ff270591b032cc1f8e342f20a04b84e5dbb31191 (diff) |
f-strings
Diffstat (limited to 'kvmd/apps')
-rw-r--r-- | kvmd/apps/__init__.py | 2 | ||||
-rw-r--r-- | kvmd/apps/htpasswd/__init__.py | 5 | ||||
-rw-r--r-- | kvmd/apps/ipmi/auth.py | 6 | ||||
-rw-r--r-- | kvmd/apps/ipmi/server.py | 4 | ||||
-rw-r--r-- | kvmd/apps/kvmd/msd.py | 2 | ||||
-rw-r--r-- | kvmd/apps/kvmd/server.py | 8 | ||||
-rw-r--r-- | kvmd/apps/kvmd/streamer.py | 4 |
7 files changed, 16 insertions, 15 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index 589836a8..a2e21b84 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -119,7 +119,7 @@ def _init_config(config_path: str, sections: List[str], override_options: List[s return config except (ConfigError, UnknownPluginError) as err: - raise SystemExit("Config error: %s" % (str(err))) + raise SystemExit(f"Config error: {err}") def _dump_config(config: Section) -> None: diff --git a/kvmd/apps/htpasswd/__init__.py b/kvmd/apps/htpasswd/__init__.py index 05d191f0..1a666d0f 100644 --- a/kvmd/apps/htpasswd/__init__.py +++ b/kvmd/apps/htpasswd/__init__.py @@ -45,7 +45,8 @@ from .. import init # ===== def _get_htpasswd_path(config: Section) -> str: if config.kvmd.auth.internal_type != "htpasswd": - raise SystemExit("Error: KVMD internal auth not using 'htpasswd' (now configured %r)" % (config.kvmd.auth.internal_type)) + raise SystemExit(f"Error: KVMD internal auth not using 'htpasswd'" + f" (now configured {config.kvmd.auth.internal_type!r})") return config.kvmd.auth.internal.file @@ -53,7 +54,7 @@ def _get_htpasswd_path(config: Section) -> str: def _get_htpasswd_for_write(config: Section) -> Generator[passlib.apache.HtpasswdFile, None, None]: path = _get_htpasswd_path(config) (tmp_fd, tmp_path) = tempfile.mkstemp( - prefix=".%s." % (os.path.basename(path)), + prefix=f".{os.path.basename(path)}.", dir=os.path.dirname(path), ) try: diff --git a/kvmd/apps/ipmi/auth.py b/kvmd/apps/ipmi/auth.py index d4c922d7..6b33216a 100644 --- a/kvmd/apps/ipmi/auth.py +++ b/kvmd/apps/ipmi/auth.py @@ -61,12 +61,12 @@ class IpmiAuthManager: continue if " -> " not in line: - raise IpmiPasswdError("Missing ' -> ' operator at line #%d" % (number)) + raise IpmiPasswdError(f"Missing ' -> ' operator at line #{number}") (left, right) = map(str.lstrip, line.split(" -> ", 1)) for (name, pair) in [("left", left), ("right", right)]: if ":" not in pair: - raise IpmiPasswdError("Missing ':' operator in %s credentials at line #%d" % (name, number)) + raise IpmiPasswdError(f"Missing ':' operator in {name} credentials at line #{number}") (ipmi_user, ipmi_passwd) = left.split(":") ipmi_user = ipmi_user.strip() @@ -75,7 +75,7 @@ class IpmiAuthManager: kvmd_user = kvmd_user.strip() if ipmi_user in credentials: - raise IpmiPasswdError("Found duplicating user %r (left) at line #%d" % (ipmi_user, number)) + raise IpmiPasswdError(f"Found duplicating user {ipmi_user!r} (left) at line #{number}") credentials[ipmi_user] = IpmiUserCredentials( ipmi_user=ipmi_user, diff --git a/kvmd/apps/ipmi/server.py b/kvmd/apps/ipmi/server.py index 3bc2ed94..0201214f 100644 --- a/kvmd/apps/ipmi/server.py +++ b/kvmd/apps/ipmi/server.py @@ -155,7 +155,7 @@ class IpmiServer(BaseIpmiServer): # pylint: disable=too-many-instance-attribute logger = get_logger(0) assert handle.startswith("/") - url = "http://%s:%d%s" % (self.__kvmd_host, self.__kvmd_port, handle) + url = f"http://{self.__kvmd_host}:{self.__kvmd_port}{handle}" credentials = self.__auth_manager.get_credentials(ipmi_session.username.decode()) logger.info("Performing %r request to %r from user %r (IPMI) as %r (KVMD)", @@ -169,7 +169,7 @@ class IpmiServer(BaseIpmiServer): # pylint: disable=too-many-instance-attribute headers={ "X-KVMD-User": credentials.kvmd_user, "X-KVMD-Passwd": credentials.kvmd_passwd, - "User-Agent": "KVMD-IPMI/%s" % (__version__), + "User-Agent": f"KVMD-IPMI/{__version__}", }, timeout=self.__kvmd_timeout, ) as response: diff --git a/kvmd/apps/kvmd/msd.py b/kvmd/apps/kvmd/msd.py index 377e591c..cb26e520 100644 --- a/kvmd/apps/kvmd/msd.py +++ b/kvmd/apps/kvmd/msd.py @@ -156,7 +156,7 @@ def _ioctl_uint32(device_file: IO, request: int) -> int: def _explore_device(device_path: str) -> _MassStorageDeviceInfo: if not stat.S_ISBLK(os.stat(device_path).st_mode): - raise RuntimeError("Not a block device: %s" % (device_path)) + raise RuntimeError(f"Not a block device: {device_path}") with open(device_path, "rb") as device_file: # size = BLKGETSIZE * BLKSSZGET diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py index b8d3aa3a..5ea1fd62 100644 --- a/kvmd/apps/kvmd/server.py +++ b/kvmd/apps/kvmd/server.py @@ -142,7 +142,7 @@ def _json_exception(err: Exception, status: int) -> aiohttp.web.Response: async def _get_multipart_field(reader: aiohttp.MultipartReader, name: str) -> aiohttp.BodyPartReader: field = await reader.next() if not field or field.name != name: - raise ValidatorError("Missing %r field" % (name)) + raise ValidatorError(f"Missing {name!r} field") return field @@ -168,7 +168,7 @@ def _exposed(http_method: str, path: str, auth_required: bool=True) -> Callable: if user: user = valid_user(user) - setattr(request, _ATTR_KVMD_AUTH_INFO, "%s (xhdr)" % (user)) + setattr(request, _ATTR_KVMD_AUTH_INFO, f"{user} (xhdr)") if not (await self._auth_manager.authorize(user, valid_passwd(passwd))): raise ForbiddenError("Forbidden") @@ -177,7 +177,7 @@ def _exposed(http_method: str, path: str, auth_required: bool=True) -> Callable: if not user: setattr(request, _ATTR_KVMD_AUTH_INFO, "- (token)") raise ForbiddenError("Forbidden") - setattr(request, _ATTR_KVMD_AUTH_INFO, "%s (token)" % (user)) + setattr(request, _ATTR_KVMD_AUTH_INFO, f"{user} (token)") else: raise UnauthorizedError("Unauthorized") @@ -204,7 +204,7 @@ def _system_task(method: Callable) -> Callable: async def wrapper(self: "Server") -> None: try: await method(self) - raise RuntimeError("Dead system task: %s" % (method)) + raise RuntimeError(f"Dead system task: {method}") except asyncio.CancelledError: pass except Exception: diff --git a/kvmd/apps/kvmd/streamer.py b/kvmd/apps/kvmd/streamer.py index c85a53bd..ef3816c1 100644 --- a/kvmd/apps/kvmd/streamer.py +++ b/kvmd/apps/kvmd/streamer.py @@ -121,8 +121,8 @@ class Streamer: # pylint: disable=too-many-instance-attributes state = None try: async with session.get( - url="http://%s:%d/state" % (self.__host, self.__port), - headers={"User-Agent": "KVMD/%s" % (__version__)}, + url=f"http://{self.__host}:{self.__port}/state", + headers={"User-Agent": f"KVMD/{__version__}"}, timeout=self.__timeout, ) as response: response.raise_for_status() |