diff options
author | Maxim Devaev <[email protected]> | 2020-09-05 01:56:36 +0300 |
---|---|---|
committer | GitHub <[email protected]> | 2020-09-05 01:56:36 +0300 |
commit | 1257408183f0f0d649bb6302776107ed6c6a36f7 (patch) | |
tree | ef19423515ca1cc3dd6d7a45a5843220cfe46bfc /kvmd/apps | |
parent | fc53759b3e7ddb0b570d35d1afb159080a805586 (diff) | |
parent | dd2ff1ec832d00a29d33d5b54ee87f9a12b5af45 (diff) |
Merge pull request #6 from OlegGirko/python-3.7
Make KVMD compatible with Python 3.7
Diffstat (limited to 'kvmd/apps')
-rw-r--r-- | kvmd/apps/kvmd/api/auth.py | 9 | ||||
-rw-r--r-- | kvmd/apps/kvmd/api/streamer.py | 5 | ||||
-rw-r--r-- | kvmd/apps/kvmd/http.py | 8 | ||||
-rw-r--r-- | kvmd/apps/kvmd/info/hw.py | 5 | ||||
-rw-r--r-- | kvmd/apps/kvmd/server.py | 3 | ||||
-rw-r--r-- | kvmd/apps/vnc/rfb/__init__.py | 5 | ||||
-rw-r--r-- | kvmd/apps/vnc/server.py | 3 |
7 files changed, 23 insertions, 15 deletions
diff --git a/kvmd/apps/kvmd/api/auth.py b/kvmd/apps/kvmd/api/auth.py index cdbeb0a6..14cd74f4 100644 --- a/kvmd/apps/kvmd/api/auth.py +++ b/kvmd/apps/kvmd/api/auth.py @@ -45,7 +45,8 @@ _COOKIE_AUTH_TOKEN = "auth_token" async def check_request_auth(auth_manager: AuthManager, exposed: HttpExposed, request: Request) -> None: if exposed.auth_required and auth_manager.is_auth_enabled(): - if (user := request.headers.get("X-KVMD-User", "")): + user = request.headers.get("X-KVMD-User", "") + if user: user = valid_user(user) passwd = request.headers.get("X-KVMD-Passwd", "") set_request_auth_info(request, f"{user} (xhdr)") @@ -53,7 +54,8 @@ async def check_request_auth(auth_manager: AuthManager, exposed: HttpExposed, re raise ForbiddenError() return - elif (token := request.cookies.get(_COOKIE_AUTH_TOKEN, "")): + token = request.cookies.get(_COOKIE_AUTH_TOKEN, "") + if token: user = auth_manager.check(valid_auth_token(token)) if not user: set_request_auth_info(request, "- (token)") @@ -61,7 +63,8 @@ async def check_request_auth(auth_manager: AuthManager, exposed: HttpExposed, re set_request_auth_info(request, f"{user} (token)") return - elif (basic_auth := request.headers.get("Authorization", "")): + basic_auth = request.headers.get("Authorization", "") + if basic_auth: if basic_auth[:6].lower() == "basic ": try: (user, passwd) = base64.b64decode(basic_auth[6:]).decode("utf-8").split(":") diff --git a/kvmd/apps/kvmd/api/streamer.py b/kvmd/apps/kvmd/api/streamer.py index 995ed836..cd5f045d 100644 --- a/kvmd/apps/kvmd/api/streamer.py +++ b/kvmd/apps/kvmd/api/streamer.py @@ -56,11 +56,12 @@ class StreamerApi: @exposed_http("GET", "/streamer/snapshot") async def __take_snapshot_handler(self, request: Request) -> Response: - if (snapshot := await self.__streamer.take_snapshot( + snapshot = await self.__streamer.take_snapshot( save=valid_bool(request.query.get("save", "false")), load=valid_bool(request.query.get("load", "false")), allow_offline=valid_bool(request.query.get("allow_offline", "false")), - )): + ) + if snapshot: if valid_bool(request.query.get("preview", "false")): data = await self.__make_preview( snapshot=snapshot, diff --git a/kvmd/apps/kvmd/http.py b/kvmd/apps/kvmd/http.py index 729c8498..e13198b1 100644 --- a/kvmd/apps/kvmd/http.py +++ b/kvmd/apps/kvmd/http.py @@ -77,8 +77,8 @@ def get_exposed_http(obj: object) -> List[HttpExposed]: auth_required=getattr(handler, _HTTP_AUTH_REQUIRED), handler=handler, ) - for name in dir(obj) - if inspect.ismethod(handler := getattr(obj, name)) and getattr(handler, _HTTP_EXPOSED, False) + for handler in [getattr(obj, name) for name in dir(obj)] + if inspect.ismethod(handler) and getattr(handler, _HTTP_EXPOSED, False) ] @@ -107,8 +107,8 @@ def get_exposed_ws(obj: object) -> List[WsExposed]: event_type=getattr(handler, _WS_EVENT_TYPE), handler=handler, ) - for name in dir(obj) - if inspect.ismethod(handler := getattr(obj, name)) and getattr(handler, _WS_EXPOSED, False) + for handler in [getattr(obj, name) for name in dir(obj)] + if inspect.ismethod(handler) and getattr(handler, _WS_EXPOSED, False) ] diff --git a/kvmd/apps/kvmd/info/hw.py b/kvmd/apps/kvmd/info/hw.py index b9b7c94e..8df8aee5 100644 --- a/kvmd/apps/kvmd/info/hw.py +++ b/kvmd/apps/kvmd/info/hw.py @@ -109,10 +109,11 @@ class HwInfoSubmanager(BaseInfoSubmanager): async def __get_throttling(self) -> Optional[Dict]: # https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=147781&start=50#p972790 - if (flags := await self.__parse_vcgencmd( + flags = await self.__parse_vcgencmd( arg="get_throttled", parser=(lambda text: int(text.split("=")[-1].strip(), 16)), - )) is not None: + ) + if flags is not None: return { "raw_flags": flags, "parsed_flags": { diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py index ac7552a8..57d8c3e9 100644 --- a/kvmd/apps/kvmd/server.py +++ b/kvmd/apps/kvmd/server.py @@ -215,7 +215,8 @@ class KvmdServer(HttpServer): # pylint: disable=too-many-arguments,too-many-ins ("desired_fps", valid_stream_fps, None), ("resolution", valid_stream_resolution, StreamerResolutionNotSupported), ]: - if (value := request.query.get(name)): + value = request.query.get(name) + if (value): if name not in current_params: assert exc_cls is not None, name raise exc_cls() diff --git a/kvmd/apps/vnc/rfb/__init__.py b/kvmd/apps/vnc/rfb/__init__.py index f10d7da2..f552321d 100644 --- a/kvmd/apps/vnc/rfb/__init__.py +++ b/kvmd/apps/vnc/rfb/__init__.py @@ -363,7 +363,8 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute } while True: msg_type = await self._read_number("B") - if (handler := handlers.get(msg_type)) is not None: + handler = handlers.get(msg_type) + if handler is not None: await handler() # type: ignore # mypy bug else: raise RfbError(f"Unknown message type: {msg_type}") @@ -372,7 +373,7 @@ class RfbClient(RfbClientStream): # pylint: disable=too-many-instance-attribute # JpegCompression may only be used when bits-per-pixel is either 16 or 32 bits_per_pixel = (await self._read_struct("xxx BB?? HHH BBB xxx"))[0] if bits_per_pixel not in [16, 32]: - raise RfbError(f"Requested unsupported {bits_per_pixel=} for Tight JPEG; required 16 or 32") + raise RfbError(f"Requested unsupported bits_per_pixel={bits_per_pixel} for Tight JPEG; required 16 or 32") async def __handle_set_encodings(self) -> None: encodings_count = (await self._read_struct("x H"))[0] diff --git a/kvmd/apps/vnc/server.py b/kvmd/apps/vnc/server.py index 28e7db62..f552e026 100644 --- a/kvmd/apps/vnc/server.py +++ b/kvmd/apps/vnc/server.py @@ -239,7 +239,8 @@ class _Client(RfbClient): # pylint: disable=too-many-instance-attributes async def _on_key_event(self, code: int, state: bool) -> None: if self.__kvmd_ws: - if (web_key := self.__symmap.get(code)) is not None: + web_key = self.__symmap.get(code) + if web_key is not None: await self.__kvmd_ws.send_key_event(web_key.name, state) async def _on_pointer_event(self, buttons: Dict[str, bool], wheel: Dict[str, int], move: Dict[str, int]) -> None: |