From: Eugene Crosser Date: Mon, 11 Jul 2022 21:13:24 +0000 (+0200) Subject: function `proto_handled()` in proto modules X-Git-Tag: 1.90~29 X-Git-Url: http://www.average.org/gitweb/?p=loctrkd.git;a=commitdiff_plain;h=ba4cb894d37f24ac333b316cf9487dfc913eaf74 function `proto_handled()` in proto modules --- diff --git a/loctrkd/beesure.py b/loctrkd/beesure.py index f3f58b6..8fa83f5 100755 --- a/loctrkd/beesure.py +++ b/loctrkd/beesure.py @@ -26,6 +26,7 @@ __all__ = ( "class_by_prefix", "enframe", "inline_response", + "proto_handled", "parse_message", "probe_buffer", "proto_by_name", @@ -408,6 +409,10 @@ def class_by_prefix( return CLASSES[proto] +def proto_handled(proto: str) -> bool: + return proto.startswith(PROTO_PREFIX) + + def proto_name(obj: Union[MetaPkt, BeeSurePkt]) -> str: return PROTO_PREFIX + ( obj.__class__.__name__ if isinstance(obj, BeeSurePkt) else obj.__name__ diff --git a/loctrkd/watch.py b/loctrkd/watch.py index 7221d2b..738cfe2 100644 --- a/loctrkd/watch.py +++ b/loctrkd/watch.py @@ -14,7 +14,9 @@ log = getLogger("loctrkd/watch") class ProtoModule: - PROTO_PREFIX: str + @staticmethod + def proto_handled(proto: str) -> bool: + ... @staticmethod def parse_message(packet: bytes, is_incoming: bool = True) -> Any: @@ -41,7 +43,7 @@ def runserver(conf: ConfigParser) -> None: zmsg = Bcast(zsub.recv()) print("I" if zmsg.is_incoming else "O", zmsg.proto, zmsg.imei) for pmod in pmods: - if zmsg.proto.startswith(pmod.PROTO_PREFIX): + if pmod.proto_handled(zmsg.proto.startswith): msg = pmod.parse_message(zmsg.packet, zmsg.is_incoming) print(msg) except KeyboardInterrupt: diff --git a/loctrkd/zx303proto.py b/loctrkd/zx303proto.py index c47c216..2c44a13 100755 --- a/loctrkd/zx303proto.py +++ b/loctrkd/zx303proto.py @@ -35,6 +35,7 @@ __all__ = ( "Stream", "class_by_prefix", "inline_response", + "proto_handled", "parse_message", "probe_buffer", "proto_by_name", @@ -875,6 +876,10 @@ def class_by_prefix( 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__