@@ -512,31 +512,30 @@ def __repr__(self) -> str:
512512
513513
514514class DNSRRSet :
515- """A set of dns records independent of the ttl."""
515+ """A set of dns records with a lookup to get the ttl."""
516516
517- __slots__ = ('_records ' , '_lookup' )
517+ __slots__ = ('_record_sets ' , '_lookup' )
518518
519- def __init__ (self , records : Iterable [DNSRecord ]) -> None :
520- """Create an RRset from records."""
521- self ._records = records
522- self ._lookup : Optional [Dict [DNSRecord , DNSRecord ]] = None
519+ def __init__ (self , record_sets : Iterable [List [ DNSRecord ] ]) -> None :
520+ """Create an RRset from records sets ."""
521+ self ._record_sets = record_sets
522+ self ._lookup : Optional [Dict [DNSRecord , float ]] = None
523523
524524 @property
525- def lookup (self ) -> Dict [DNSRecord , DNSRecord ]:
525+ def lookup (self ) -> Dict [DNSRecord , float ]:
526+ """Return the lookup table."""
527+ return self ._get_lookup ()
528+
529+ def _get_lookup (self ) -> Dict [DNSRecord , float ]:
530+ """Return the lookup table, building it if needed."""
526531 if self ._lookup is None :
527- # Build the hash table so we can lookup the record independent of the ttl
528- self ._lookup = {record : record for record in self ._records }
532+ # Build the hash table so we can lookup the record ttl
533+ self ._lookup = {record : record . ttl for record_sets in self ._record_sets for record in record_sets }
529534 return self ._lookup
530535
531536 def suppresses (self , record : _DNSRecord ) -> bool :
532537 """Returns true if any answer in the rrset can suffice for the
533538 information held in this record."""
534- if self ._lookup is None :
535- other = self .lookup .get (record )
536- else :
537- other = self ._lookup .get (record )
538- return bool (other and other .ttl > (record .ttl / 2 ))
539-
540- def __contains__ (self , record : DNSRecord ) -> bool :
541- """Returns true if the rrset contains the record."""
542- return record in self .lookup
539+ lookup = self ._get_lookup ()
540+ other_ttl = lookup .get (record )
541+ return bool (other_ttl and other_ttl > (record .ttl / 2 ))
0 commit comments