]> average.org Git - loctrkd.git/blobdiff - loctrkd/zx303proto.py
collector: close old connection on new login
[loctrkd.git] / loctrkd / zx303proto.py
index 2c44a1382b1058b7b0a9e2f0325fde57c3b107a5..8c21418cd7a13c9af9f03c57d9d345f8c5592a50 100755 (executable)
@@ -38,7 +38,6 @@ __all__ = (
     "proto_handled",
     "parse_message",
     "probe_buffer",
-    "proto_by_name",
     "proto_name",
     "DecodeError",
     "Respond",
@@ -865,6 +864,10 @@ if True:  # just to indent the code, sorry!
 def class_by_prefix(
     prefix: str,
 ) -> Union[Type[GPS303Pkt], List[Tuple[str, int]]]:
+    if prefix.startswith(PROTO_PREFIX):
+        pname = prefix[len(PROTO_PREFIX) :]
+    else:
+        raise KeyError(pname)
     lst = [
         (name, proto)
         for name, proto in PROTOS.items()
@@ -886,10 +889,6 @@ def proto_name(obj: Union[MetaPkt, GPS303Pkt]) -> str:
     )
 
 
-def proto_by_name(name: str) -> int:
-    return PROTOS.get(name, -1)
-
-
 def proto_of_message(packet: bytes) -> str:
     return proto_name(CLASSES.get(packet[1], UNKNOWN))