Skip to content

Commit

Permalink
Optionally include the name of the entry.
Browse files Browse the repository at this point in the history
This allows providing a descriptive name for the various entries.
  • Loading branch information
Flameeyes committed Dec 26, 2023
1 parent 82584f2 commit b68adc1
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion ipv6_in_real_life/data_structures.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,20 @@ def as_json(self) -> HostJson:
class Entity:
country: str
category: str
name: str
main_host: Host
additional_hosts: Sequence[Host]
ipv6_ready: Optional[bool] = None

@classmethod
def from_json(cls, json_entity: Dict[str, Any]) -> "Entity":
main_host = Host(json_entity["main_host"])

return cls(
json_entity["country"],
json_entity["category"],
Host(json_entity["main_host"]),
json_entity.get("name", main_host.name),
main_host,
tuple(Host(host) for host in json_entity.get("additional_hosts", [])),
)

Expand All @@ -86,6 +90,7 @@ def as_dict(
self,
) -> EntityJson:
return {
"name": self.name,
"main_host": self.main_host.as_json(),
"additional_hosts": [host.as_json() for host in self.additional_hosts],
}
Expand Down

0 comments on commit b68adc1

Please sign in to comment.