diff options
author | Oleg Girko <[email protected]> | 2020-08-18 03:44:06 +0300 |
---|---|---|
committer | Oleg Girko <[email protected]> | 2020-09-01 19:24:13 +0300 |
commit | 2dbf11428f01b748619ac5b25215c7d7a0b07dbc (patch) | |
tree | abdc93c161c4c0678106dc66ffde3f66b98ef0c4 /kvmd/apps | |
parent | 5307765399c1a3280eeb33380047195a118eb935 (diff) |
Remove all uses of assignment expressions.
This is needed to port to Python 3.7 because
Raspbian 10 doesn't have Python 3.8.
Signed-off-by: Oleg Girko <[email protected]>
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 | 3 | ||||
-rw-r--r-- | kvmd/apps/vnc/server.py | 3 |
7 files changed, 22 insertions, 14 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 5208f25d..30d5c035 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..765d1574 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}") 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: |