| 183 | |
| 184 | @classmethod |
| 185 | def from_json(cls, data: dict[str, Any]) -> Self: |
| 186 | inst = cls( |
| 187 | name=data["name"], |
| 188 | type=types.from_str(data["type"]), |
| 189 | class_=classes.from_str(data["class"]), |
| 190 | ttl=data["ttl"], |
| 191 | data=b"", |
| 192 | ) |
| 193 | |
| 194 | d: str = data["data"] |
| 195 | try: |
| 196 | match inst.type: |
| 197 | case types.A: |
| 198 | inst.ipv4_address = IPv4Address(d) |
| 199 | case types.AAAA: |
| 200 | inst.ipv6_address = IPv6Address(d) |
| 201 | case types.NS | types.CNAME | types.PTR: |
| 202 | inst.domain_name = d |
| 203 | case types.TXT: |
| 204 | inst.text = d |
| 205 | case types.HTTPS: |
| 206 | record = HTTPSRecord.from_json(cast(HTTPSRecordJSON, d)) |
| 207 | inst.data = https_records.pack(record) |
| 208 | case _: |
| 209 | raise ValueError |
| 210 | except Exception: |
| 211 | inst.data = bytes.fromhex(d.removeprefix("0x").partition(" (")[0]) |
| 212 | |
| 213 | return inst |
| 214 | |
| 215 | @classmethod |
| 216 | def A(cls, name: str, ip: IPv4Address, *, ttl: int = DEFAULT_TTL) -> ResourceRecord: |