summaryrefslogtreecommitdiff
path: root/kvmd/apps
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-05-11 08:06:44 +0300
committerDevaev Maxim <[email protected]>2020-05-11 08:06:44 +0300
commit98a176f7408350741f89547ea6d1d6e519965cbf (patch)
tree872a8f1c288975c118e0384e44973c944ea5b1f2 /kvmd/apps
parent60b6c219d91addfd79a30cfa9c20b398eb3391ae (diff)
lint fixes
Diffstat (limited to 'kvmd/apps')
-rw-r--r--kvmd/apps/kvmd/api/log.py11
-rw-r--r--kvmd/apps/kvmd/http.py2
-rw-r--r--kvmd/apps/vnc/kvmd.py3
-rw-r--r--kvmd/apps/vnc/streamer.py4
4 files changed, 12 insertions, 8 deletions
diff --git a/kvmd/apps/kvmd/api/log.py b/kvmd/apps/kvmd/api/log.py
index 9a6d8853..72ce8190 100644
--- a/kvmd/apps/kvmd/api/log.py
+++ b/kvmd/apps/kvmd/api/log.py
@@ -20,8 +20,6 @@
# ========================================================================== #
-from typing import Optional
-
import aiohttp.web
from ....validators.basic import valid_bool
@@ -44,14 +42,15 @@ class LogApi:
async def __log_handler(self, request: aiohttp.web.Request) -> aiohttp.web.StreamResponse:
seek = valid_log_seek(request.query.get("seek", "0"))
follow = valid_bool(request.query.get("follow", "false"))
- response: Optional[aiohttp.web.StreamResponse] = None
+
+ response = aiohttp.web.StreamResponse(status=200, reason="OK", headers={"Content-Type": "text/plain"})
+ await response.prepare(request)
+
async for record in self.__log_reader.poll_log(seek, follow):
- if response is None:
- response = aiohttp.web.StreamResponse(status=200, reason="OK", headers={"Content-Type": "text/plain"})
- await response.prepare(request)
await response.write(("[%s %s] --- %s" % (
record["dt"].strftime("%Y-%m-%d %H:%M:%S"),
record["service"],
record["msg"],
)).encode("utf-8") + b"\r\n")
+
return response
diff --git a/kvmd/apps/kvmd/http.py b/kvmd/apps/kvmd/http.py
index a43d7d57..69dfa6ff 100644
--- a/kvmd/apps/kvmd/http.py
+++ b/kvmd/apps/kvmd/http.py
@@ -138,6 +138,8 @@ def make_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 isinstance(field, aiohttp.BodyPartReader):
+ raise ValidatorError(f"Expected body part as {name!r} field")
if not field or field.name != name:
raise ValidatorError(f"Missing {name!r} field")
return field
diff --git a/kvmd/apps/vnc/kvmd.py b/kvmd/apps/vnc/kvmd.py
index 5d130b02..6d492d5e 100644
--- a/kvmd/apps/vnc/kvmd.py
+++ b/kvmd/apps/vnc/kvmd.py
@@ -23,6 +23,7 @@
import contextlib
from typing import Dict
+from typing import AsyncGenerator
import aiohttp
@@ -64,7 +65,7 @@ class KvmdClient:
raise
@contextlib.asynccontextmanager
- async def ws(self, user: str, passwd: str) -> aiohttp.ClientWebSocketResponse: # pylint: disable=invalid-name
+ async def ws(self, user: str, passwd: str) -> AsyncGenerator[aiohttp.ClientWebSocketResponse, None]:
async with self.__make_session(user, passwd) as session:
async with session.ws_connect(
url=f"http://{self.__host}:{self.__port}/ws",
diff --git a/kvmd/apps/vnc/streamer.py b/kvmd/apps/vnc/streamer.py
index 62fce849..fd2232ee 100644
--- a/kvmd/apps/vnc/streamer.py
+++ b/kvmd/apps/vnc/streamer.py
@@ -61,7 +61,9 @@ class StreamerClient:
response.raise_for_status()
reader = aiohttp.MultipartReader.from_response(response)
while True:
- frame = await reader.next()
+ frame = await reader.next() # pylint: disable=not-callable
+ if not isinstance(frame, aiohttp.BodyPartReader):
+ raise RuntimeError("Expected body part")
yield (
(frame.headers["X-UStreamer-Online"] == "true"),
int(frame.headers["X-UStreamer-Width"]),