diff options
author | Maxim Devaev <[email protected]> | 2022-06-19 00:02:48 +0300 |
---|---|---|
committer | Maxim Devaev <[email protected]> | 2022-06-19 00:02:48 +0300 |
commit | 74e81b6e0345f37695c6cb05dd4fa2e489fd9026 (patch) | |
tree | 6e8b13d83fb4892aef2b883a27c447802e09f093 /kvmd | |
parent | af129106cd4c0b5c7c6db75cee98ab3de6f43ad8 (diff) |
refactoring
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/htserver.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/kvmd/htserver.py b/kvmd/htserver.py index d3919310..eb364767 100644 --- a/kvmd/htserver.py +++ b/kvmd/htserver.py @@ -208,6 +208,19 @@ async def stream_json_exception(response: StreamResponse, err: Exception) -> Non }, False) +def parse_ws_event(msg: str) -> Tuple[str, Dict]: + data = json.loads(msg) + if not isinstance(data, dict): + raise RuntimeError("Top-level event structure is not a dict") + event_type = data.get("event_type") + if not isinstance(event_type, str): + raise RuntimeError("event_type must be a string") + event = data["event"] + if not isinstance(event, dict): + raise RuntimeError("event must be a dict") + return (event_type, event) + + # ===== _REQUEST_AUTH_INFO = "_kvmd_auth_info" @@ -323,7 +336,7 @@ class HttpServer: if msg.type != WSMsgType.TEXT: break try: - (event_type, event) = self.__parse_ws_event(msg.data) + (event_type, event) = parse_ws_event(msg.data) except Exception as err: logger.error("Can't parse JSON event from websocket: %r", err) else: @@ -363,18 +376,6 @@ class HttpServer: pass await self._on_ws_closed() - def __parse_ws_event(self, msg: str) -> Tuple[str, Dict]: - data = json.loads(msg) - if not isinstance(data, dict): - raise RuntimeError("Top-level event structure is not a dict") - event_type = data.get("event_type") - if not isinstance(event_type, str): - raise RuntimeError("event_type must be a string") - event = data["event"] - if not isinstance(event, dict): - raise RuntimeError("event must be a dict") - return (event_type, event) - # ===== async def _check_request_auth(self, exposed: HttpExposed, request: Request) -> None: |