summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-05-17 16:11:49 +0300
committerDevaev Maxim <[email protected]>2020-05-17 16:11:49 +0300
commit8a13f62911380ee63029d4727b3e9e9df747be1c (patch)
tree2c5cb23cc73e113c8e905c243365cf64fde53a84
parent1fd33bc8ed29c3aaeb6c9971e5879c04113246a3 (diff)
refactoring
-rw-r--r--kvmd/apps/kvmd/api/atx.py9
-rw-r--r--kvmd/apps/kvmd/api/hid.py16
-rw-r--r--kvmd/apps/kvmd/api/log.py7
-rw-r--r--kvmd/apps/kvmd/api/msd.py18
-rw-r--r--kvmd/apps/kvmd/api/wol.py7
5 files changed, 31 insertions, 26 deletions
diff --git a/kvmd/apps/kvmd/api/atx.py b/kvmd/apps/kvmd/api/atx.py
index 176c4e77..f4317c3c 100644
--- a/kvmd/apps/kvmd/api/atx.py
+++ b/kvmd/apps/kvmd/api/atx.py
@@ -20,7 +20,8 @@
# ========================================================================== #
-import aiohttp.web
+from aiohttp.web import Request
+from aiohttp.web import Response
from ....plugins.atx import BaseAtx
@@ -39,11 +40,11 @@ class AtxApi:
# =====
@exposed_http("GET", "/atx")
- async def __state_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __state_handler(self, _: Request) -> Response:
return make_json_response(self.__atx.get_state())
@exposed_http("POST", "/atx/power")
- async def __power_handler(self, request: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __power_handler(self, request: Request) -> Response:
action = valid_atx_power_action(request.query.get("action"))
processing = await ({
"on": self.__atx.power_on,
@@ -54,7 +55,7 @@ class AtxApi:
return make_json_response({"processing": processing})
@exposed_http("POST", "/atx/click")
- async def __click_handler(self, request: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __click_handler(self, request: Request) -> Response:
button = valid_atx_button(request.query.get("button"))
await ({
"power": self.__atx.click_power,
diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py
index fad22718..9d18b2d5 100644
--- a/kvmd/apps/kvmd/api/hid.py
+++ b/kvmd/apps/kvmd/api/hid.py
@@ -22,7 +22,9 @@
from typing import Dict
-import aiohttp.web
+from aiohttp.web import Request
+from aiohttp.web import Response
+from aiohttp.web import WebSocketResponse
from ....plugins.hid import BaseHid
@@ -46,18 +48,18 @@ class HidApi:
# =====
@exposed_http("GET", "/hid")
- async def __state_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __state_handler(self, _: Request) -> Response:
return make_json_response(await self.__hid.get_state())
@exposed_http("POST", "/hid/reset")
- async def __reset_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __reset_handler(self, _: Request) -> Response:
await self.__hid.reset()
return make_json_response()
# =====
@exposed_ws("key")
- async def __ws_key_handler(self, _: aiohttp.web.WebSocketResponse, event: Dict) -> None:
+ async def __ws_key_handler(self, _: WebSocketResponse, event: Dict) -> None:
try:
key = valid_hid_key(event["key"])
state = valid_bool(event["state"])
@@ -66,7 +68,7 @@ class HidApi:
await self.__hid.send_key_event(key, state)
@exposed_ws("mouse_button")
- async def __ws_mouse_button_handler(self, _: aiohttp.web.WebSocketResponse, event: Dict) -> None:
+ async def __ws_mouse_button_handler(self, _: WebSocketResponse, event: Dict) -> None:
try:
button = valid_hid_mouse_button(event["button"])
state = valid_bool(event["state"])
@@ -75,7 +77,7 @@ class HidApi:
await self.__hid.send_mouse_button_event(button, state)
@exposed_ws("mouse_move")
- async def __ws_mouse_move_handler(self, _: aiohttp.web.WebSocketResponse, event: Dict) -> None:
+ async def __ws_mouse_move_handler(self, _: WebSocketResponse, event: Dict) -> None:
try:
to_x = valid_hid_mouse_move(event["to"]["x"])
to_y = valid_hid_mouse_move(event["to"]["y"])
@@ -84,7 +86,7 @@ class HidApi:
await self.__hid.send_mouse_move_event(to_x, to_y)
@exposed_ws("mouse_wheel")
- async def __ws_mouse_wheel_handler(self, _: aiohttp.web.WebSocketResponse, event: Dict) -> None:
+ async def __ws_mouse_wheel_handler(self, _: WebSocketResponse, event: Dict) -> None:
try:
delta_x = valid_hid_mouse_wheel(event["delta"]["x"])
delta_y = valid_hid_mouse_wheel(event["delta"]["y"])
diff --git a/kvmd/apps/kvmd/api/log.py b/kvmd/apps/kvmd/api/log.py
index 72ce8190..7dec92a3 100644
--- a/kvmd/apps/kvmd/api/log.py
+++ b/kvmd/apps/kvmd/api/log.py
@@ -20,7 +20,8 @@
# ========================================================================== #
-import aiohttp.web
+from aiohttp.web import Request
+from aiohttp.web import StreamResponse
from ....validators.basic import valid_bool
@@ -39,11 +40,11 @@ class LogApi:
# =====
@exposed_http("GET", "/log")
- async def __log_handler(self, request: aiohttp.web.Request) -> aiohttp.web.StreamResponse:
+ async def __log_handler(self, request: Request) -> StreamResponse:
seek = valid_log_seek(request.query.get("seek", "0"))
follow = valid_bool(request.query.get("follow", "false"))
- response = aiohttp.web.StreamResponse(status=200, reason="OK", headers={"Content-Type": "text/plain"})
+ response = 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):
diff --git a/kvmd/apps/kvmd/api/msd.py b/kvmd/apps/kvmd/api/msd.py
index 0ab2e9b4..c41f651d 100644
--- a/kvmd/apps/kvmd/api/msd.py
+++ b/kvmd/apps/kvmd/api/msd.py
@@ -20,8 +20,8 @@
# ========================================================================== #
-import aiohttp
-import aiohttp.web
+from aiohttp.web import Request
+from aiohttp.web import Response
from ....logging import get_logger
@@ -45,11 +45,11 @@ class MsdApi:
# =====
@exposed_http("GET", "/msd")
- async def __state_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __state_handler(self, _: Request) -> Response:
return make_json_response(await self.__msd.get_state())
@exposed_http("POST", "/msd/set_params")
- async def __set_params_handler(self, request: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __set_params_handler(self, request: Request) -> Response:
params = {
key: validator(request.query.get(param))
for (param, key, validator) in [
@@ -62,17 +62,17 @@ class MsdApi:
return make_json_response()
@exposed_http("POST", "/msd/connect")
- async def __connect_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __connect_handler(self, _: Request) -> Response:
await self.__msd.connect()
return make_json_response()
@exposed_http("POST", "/msd/disconnect")
- async def __disconnect_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __disconnect_handler(self, _: Request) -> Response:
await self.__msd.disconnect()
return make_json_response()
@exposed_http("POST", "/msd/write")
- async def __write_handler(self, request: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __write_handler(self, request: Request) -> Response:
logger = get_logger(0)
reader = await request.multipart()
name = ""
@@ -96,11 +96,11 @@ class MsdApi:
return make_json_response({"image": {"name": name, "size": written}})
@exposed_http("POST", "/msd/remove")
- async def __remove_handler(self, request: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __remove_handler(self, request: Request) -> Response:
await self.__msd.remove(valid_msd_image_name(request.query.get("image")))
return make_json_response()
@exposed_http("POST", "/msd/reset")
- async def __reset_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __reset_handler(self, _: Request) -> Response:
await self.__msd.reset()
return make_json_response()
diff --git a/kvmd/apps/kvmd/api/wol.py b/kvmd/apps/kvmd/api/wol.py
index c919728e..01f273a8 100644
--- a/kvmd/apps/kvmd/api/wol.py
+++ b/kvmd/apps/kvmd/api/wol.py
@@ -20,7 +20,8 @@
# ========================================================================== #
-import aiohttp.web
+from aiohttp.web import Request
+from aiohttp.web import Response
from ..wol import WakeOnLan
@@ -36,10 +37,10 @@ class WolApi:
# =====
@exposed_http("GET", "/wol")
- async def __wol_state_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __wol_state_handler(self, _: Request) -> Response:
return make_json_response(self.__wol.get_state())
@exposed_http("POST", "/wol/wakeup")
- async def __wol_wakeup_handler(self, _: aiohttp.web.Request) -> aiohttp.web.Response:
+ async def __wol_wakeup_handler(self, _: Request) -> Response:
await self.__wol.wakeup()
return make_json_response()