f-strings

This commit is contained in:
Devaev Maxim
2019-06-28 18:59:36 +03:00
parent ff270591b0
commit ef3c62a7af
15 changed files with 40 additions and 38 deletions

View File

@@ -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

View File

@@ -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:

View File

@@ -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()