|
22 | 22 |
|
23 | 23 | import enum |
24 | 24 | import socket |
25 | | -from typing import Any, Dict, Iterable, Optional, TYPE_CHECKING, Tuple, Union, cast |
| 25 | +from typing import Any, Dict, Iterable, List, Optional, TYPE_CHECKING, Tuple, Union, cast |
26 | 26 |
|
27 | 27 | from ._exceptions import AbstractMethodException |
28 | 28 | from ._utils.net import _is_v6_address |
@@ -116,11 +116,7 @@ class DNSQuestion(DNSEntry): |
116 | 116 |
|
117 | 117 | def answered_by(self, rec: 'DNSRecord') -> bool: |
118 | 118 | """Returns true if the question is answered by the record""" |
119 | | - return ( |
120 | | - self.class_ == rec.class_ |
121 | | - and (self.type == rec.type or self.type == _TYPE_ANY) |
122 | | - and self.name == rec.name |
123 | | - ) |
| 119 | + return self.class_ == rec.class_ and self.type in (rec.type, _TYPE_ANY) and self.name == rec.name |
124 | 120 |
|
125 | 121 | def __hash__(self) -> int: |
126 | 122 | return hash((self.name, self.class_, self.type)) |
@@ -446,6 +442,44 @@ def __repr__(self) -> str: |
446 | 442 | return self.to_string("%s:%s" % (self.server, self.port)) |
447 | 443 |
|
448 | 444 |
|
| 445 | +class DNSNsec(DNSRecord): |
| 446 | + |
| 447 | + """A DNS NSEC record""" |
| 448 | + |
| 449 | + __slots__ = ('next', 'rdtypes') |
| 450 | + |
| 451 | + def __init__( |
| 452 | + self, |
| 453 | + name: str, |
| 454 | + type_: int, |
| 455 | + class_: int, |
| 456 | + ttl: int, |
| 457 | + next: str, |
| 458 | + rdtypes: List[int], |
| 459 | + created: Optional[float] = None, |
| 460 | + ) -> None: |
| 461 | + super().__init__(name, type_, class_, ttl, created) |
| 462 | + self.next = next |
| 463 | + self.rdtypes = rdtypes |
| 464 | + |
| 465 | + def __eq__(self, other: Any) -> bool: |
| 466 | + """Tests equality on cpu and os""" |
| 467 | + return ( |
| 468 | + isinstance(other, DNSNsec) |
| 469 | + and self.next == other.next |
| 470 | + and self.rdtypes == other.rdtypes |
| 471 | + and DNSEntry.__eq__(self, other) |
| 472 | + ) |
| 473 | + |
| 474 | + def __hash__(self) -> int: |
| 475 | + """Hash to compare like DNSNSec.""" |
| 476 | + return hash((*self._entry_tuple(), self.next, *self.rdtypes)) |
| 477 | + |
| 478 | + def __repr__(self) -> str: |
| 479 | + """String representation""" |
| 480 | + return self.to_string(self.next + "," + "|".join([self.get_type(type_) for type_ in self.rdtypes])) |
| 481 | + |
| 482 | + |
449 | 483 | class DNSRRSet: |
450 | 484 | """A set of dns records independent of the ttl.""" |
451 | 485 |
|
|
0 commit comments