summaryrefslogtreecommitdiff
path: root/kvmd/htserver.py
diff options
context:
space:
mode:
authorMaxim Devaev <[email protected]>2023-06-07 01:21:23 +0300
committerMaxim Devaev <[email protected]>2023-06-07 01:21:23 +0300
commit9c694da00c7d93cbff3aa910ffdeeb8dded691c0 (patch)
tree85965b4990c8d1f3f52ac2651f025c4e87381db9 /kvmd/htserver.py
parent7c507810f0a2a753ea152df3ce1013588006bda4 (diff)
simplified binary expose_ws()
Diffstat (limited to 'kvmd/htserver.py')
-rw-r--r--kvmd/htserver.py14
1 files changed, 6 insertions, 8 deletions
diff --git a/kvmd/htserver.py b/kvmd/htserver.py
index ef2445f8..fa2aedc4 100644
--- a/kvmd/htserver.py
+++ b/kvmd/htserver.py
@@ -132,15 +132,10 @@ _WS_BINARY = "_ws_binary"
_WS_EVENT_TYPE = "_ws_event_type"
-def exposed_ws(event_type: (str | int), binary: bool=False) -> Callable:
- if binary:
- assert isinstance(event_type, int)
- else:
- assert isinstance(event_type, str)
-
+def exposed_ws(event_type: (str | int)) -> Callable:
def set_attrs(handler: Callable) -> Callable:
setattr(handler, _WS_EXPOSED, True)
- setattr(handler, _WS_BINARY, binary)
+ setattr(handler, _WS_BINARY, isinstance(event_type, int))
setattr(handler, _WS_EVENT_TYPE, str(event_type))
return handler
return set_attrs
@@ -341,8 +336,11 @@ class HttpServer:
def __add_exposed_ws(self, exposed: WsExposed) -> None:
if exposed.binary:
- self.__ws_bin_handlers[int(exposed.event_type)] = exposed.handler
+ event_type = int(exposed.event_type)
+ assert event_type not in self.__ws_bin_handlers
+ self.__ws_bin_handlers[event_type] = exposed.handler
else:
+ assert exposed.event_type not in self.__ws_handlers
self.__ws_handlers[exposed.event_type] = exposed.handler
# =====