X-Git-Url: http://average.org/gitweb/?a=blobdiff_plain;f=gps303%2Fgps303proto.py;h=cc4ab3f629279ab932292489e122a41ad2efcf33;hb=602261422a9c34a1ac5ecde75ad87dde7fea6d8c;hp=acfaea63c272aa74bc676dcac90765d027c8ddd2;hpb=3f74a195c346809d3075b1351705eb9ad543afd5;p=loctrkd.git diff --git a/gps303/gps303proto.py b/gps303/gps303proto.py index acfaea6..cc4ab3f 100755 --- a/gps303/gps303proto.py +++ b/gps303/gps303proto.py @@ -21,6 +21,7 @@ from logging import getLogger from struct import pack, unpack __all__ = ( + "class_by_prefix", "handle_packet", "inline_response", "make_object", @@ -536,6 +537,15 @@ if True: # just to indent the code, sorry! PROTOS[cls.__name__] = cls.PROTO +def class_by_prefix(prefix): + lst = [(name, proto) for name, proto in PROTOS.items() + if name.upper().startswith(prefix.upper())] + if len(lst) != 1: + return lst + _, proto = lst[0] + return CLASSES[proto] + + def proto_by_name(name): return PROTOS.get(name, -1)