From 72c570e096839c923df9e0fbf76a068627698838 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Wed, 22 Feb 2023 08:55:06 +1000 Subject: [PATCH] scanner: pass the Enum to the Entry class So we can compose the fqdn (and possibly do value checks and whatnot) --- proto/ei-scanner | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/proto/ei-scanner b/proto/ei-scanner index 302efa8..17a5f01 100755 --- a/proto/ei-scanner +++ b/proto/ei-scanner @@ -181,14 +181,19 @@ class Entry: name: str = attr.ib() value: int = attr.ib() + enum: "Enum" = attr.ib() summary: str = attr.ib() since: int = attr.ib() @classmethod def create( - cls, name: str, value: int, summary: str = "", since: int = 1 + cls, name: str, value: int, enum: "Enum", summary: str = "", since: int = 1 ) -> "Entry": - return cls(name=name, value=value, summary=summary, since=since) + return cls(name=name, value=value, enum=enum, summary=summary, since=since) + + @property + def fqdn(self) -> str: + return f"{self.enum.fqdn}_{self.name}" @attr.s @@ -532,7 +537,13 @@ class Protocol(xml.sax.handler.ContentHandler): value = int(attrs["value"]) summary = attrs.get("summary", "") since = int(attrs.get("since", 1)) - entry = Entry.create(name=name, value=value, summary=summary, since=since) + entry = Entry.create( + name=name, + value=value, + enum=self.current_message, + summary=summary, + since=since, + ) try: self.current_message.add_entry(entry) except ValueError as e: