scanner: pass the Enum to the Entry class

So we can compose the fqdn (and possibly do value checks and whatnot)
This commit is contained in:
Peter Hutterer 2023-02-22 08:55:06 +10:00
parent 1c9ce9b680
commit 72c570e096

View file

@ -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: