1
0
mirror of https://github.com/craigerl/aprsd.git synced 2024-11-21 23:55:17 -05:00

optimized Packet.get()

This commit is contained in:
Hemna 2024-11-05 15:04:48 -05:00
parent 224686cac5
commit 579d0c95a0

View File

@ -63,15 +63,11 @@ def _init_msgNo(): # noqa: N802
def _translate_fields(raw: dict) -> dict: def _translate_fields(raw: dict) -> dict:
translate_fields = { # Direct key checks instead of iteration
"from": "from_call", if "from" in raw:
"to": "to_call", raw["from_call"] = raw.pop("from")
} if "to" in raw:
# First translate some fields raw["to_call"] = raw.pop("to")
for key in translate_fields:
if key in raw:
raw[translate_fields[key]] = raw[key]
del raw[key]
# addresse overrides to_call # addresse overrides to_call
if "addresse" in raw: if "addresse" in raw:
@ -110,11 +106,7 @@ class Packet:
via: Optional[str] = field(default=None, compare=False, hash=False) via: Optional[str] = field(default=None, compare=False, hash=False)
def get(self, key: str, default: Optional[str] = None): def get(self, key: str, default: Optional[str] = None):
"""Emulate a getter on a dict.""" return getattr(self, key, default)
if hasattr(self, key):
return getattr(self, key)
else:
return default
@property @property
def key(self) -> str: def key(self) -> str: