]> average.org Git - loctrkd.git/blobdiff - loctrkd/zx303proto.py
beesure: remove the PROTO attribute
[loctrkd.git] / loctrkd / zx303proto.py
index c47c216134c1e6ff737d01c4107c79351c3c07ea..4d5730304fbead5492db2c1b08f5bf86381a0618 100755 (executable)
@@ -35,9 +35,9 @@ __all__ = (
     "Stream",
     "class_by_prefix",
     "inline_response",
+    "proto_handled",
     "parse_message",
     "probe_buffer",
-    "proto_by_name",
     "proto_name",
     "DecodeError",
     "Respond",
@@ -863,28 +863,32 @@ if True:  # just to indent the code, sorry!
 
 def class_by_prefix(
     prefix: str,
-) -> Union[Type[GPS303Pkt], List[Tuple[str, int]]]:
+) -> Union[Type[GPS303Pkt], List[str]]:
+    if prefix.startswith(PROTO_PREFIX):
+        pname = prefix[len(PROTO_PREFIX) :]
+    else:
+        raise KeyError(pname)
     lst = [
         (name, proto)
         for name, proto in PROTOS.items()
         if name.upper().startswith(prefix.upper())
     ]
     if len(lst) != 1:
-        return lst
+        return [name for name, _ in lst]
     _, proto = lst[0]
     return CLASSES[proto]
 
 
+def proto_handled(proto: str) -> bool:
+    return proto.startswith(PROTO_PREFIX)
+
+
 def proto_name(obj: Union[MetaPkt, GPS303Pkt]) -> str:
     return PROTO_PREFIX + (
         obj.__class__.__name__ if isinstance(obj, GPS303Pkt) else obj.__name__
     )
 
 
-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))