Reconstruct a DNS message from JSON.
(cls, data: Any)
| 535 | |
| 536 | @classmethod |
| 537 | def from_json(cls, data: Any) -> DNSMessage: |
| 538 | """Reconstruct a DNS message from JSON.""" |
| 539 | inst = cls( |
| 540 | id=data["id"], |
| 541 | query=data["query"], |
| 542 | op_code=op_codes.from_str(data["op_code"]), |
| 543 | authoritative_answer=data["authoritative_answer"], |
| 544 | truncation=data["truncation"], |
| 545 | recursion_desired=data["recursion_desired"], |
| 546 | recursion_available=data["recursion_available"], |
| 547 | reserved=0, |
| 548 | response_code=response_codes.from_str(data["response_code"]), |
| 549 | questions=[Question.from_json(x) for x in data["questions"]], |
| 550 | answers=[ResourceRecord.from_json(x) for x in data["answers"]], |
| 551 | authorities=[ResourceRecord.from_json(x) for x in data["authorities"]], |
| 552 | additionals=[ResourceRecord.from_json(x) for x in data["additionals"]], |
| 553 | ) |
| 554 | if ts := data.get("timestamp"): |
| 555 | inst.timestamp = ts |
| 556 | return inst |
| 557 | |
| 558 | def copy(self) -> DNSMessage: |
| 559 | # we keep the copy semantics but change the ID generation |