@@ -79,21 +79,17 @@ def __eq__(self, other: Any) -> bool:
7979 """Equal when key, type and class match."""
8080 return isinstance (other , DNSEntry ) and self ._dns_entry_matches (other )
8181
82- @property
83- def type_label (self ) -> str :
84- """Human readable label for the record type."""
85- return _type_label (self .type )
86-
8782 @property
8883 def class_label (self ) -> str :
8984 """Human readable label for the record class."""
9085 return _class_label (self .class_ )
9186
92- def _display_fields (self ) -> list [tuple [str , str ]]:
93- fields = [("name" , self .name ), ("type" , self .type_label ), ("class" , self .class_label )]
94- if self .unique :
95- fields .append (("" , "unique" ))
96- return fields
87+ def entry_to_string (self , hdr : str , other : bytes | str | None ) -> str :
88+ """Compatibility alias rendering through the display formatter."""
89+ fields = self ._display_fields ()
90+ if other is not None :
91+ fields .append (("data" , str (other )))
92+ return _format_display (hdr , fields )
9793
9894 @staticmethod
9995 def get_class_ (class_ : int ) -> str :
@@ -105,12 +101,16 @@ def get_type(t: int) -> str:
105101 """Compatibility alias for the type_label property."""
106102 return _type_label (t )
107103
108- def entry_to_string (self , hdr : str , other : bytes | str | None ) -> str :
109- """Compatibility alias rendering through the display formatter."""
110- fields = self ._display_fields ()
111- if other is not None :
112- fields .append (("data" , str (other )))
113- return _format_display (hdr , fields )
104+ @property
105+ def type_label (self ) -> str :
106+ """Human readable label for the record type."""
107+ return _type_label (self .type )
108+
109+ def _display_fields (self ) -> list [tuple [str , str ]]:
110+ fields = [("name" , self .name ), ("type" , self .type_label ), ("class" , self .class_label )]
111+ if self .unique :
112+ fields .append (("" , "unique" ))
113+ return fields
114114
115115 def _dns_entry_matches (self , other : DNSEntry ) -> bool :
116116 return self .key == other .key and self .type == other .type and self .class_ == other .class_
@@ -222,35 +222,35 @@ def suppressed_by(self, msg: DNSIncoming) -> bool:
222222 return True
223223 return False
224224
225+ def to_string (self , other : bytes | str ) -> str :
226+ """Compatibility alias rendering through the display formatter."""
227+ return self ._repr_with (("data" , str (other )))
228+
225229 def write (self , out : DNSOutgoing ) -> None :
226230 raise AbstractMethodException (f"{ type (self ).__name__ } is missing write" )
227231
232+ def _display_fields (self ) -> list [tuple [str , str ]]:
233+ remaining = int (self .get_remaining_ttl (current_time_millis ()))
234+ return [* DNSEntry ._display_fields (self ), ("ttl" , f"{ self .ttl } ({ remaining } remaining)" )]
235+
228236 def _fast_init_record (self , name : str , type_ : _int , class_ : _int , ttl : _int , created : _float ) -> None :
229237 """Fast init for reuse."""
230238 self ._fast_init_entry (name , type_ , class_ )
231239 self .ttl = ttl
232240 self .created = created
233241
242+ def _repr_with (self , * details : tuple [str , str ]) -> str :
243+ return _format_display (type (self ).__name__ , [* self ._display_fields (), * details ])
244+
234245 def _set_created_ttl (self , created : _float , ttl : _int ) -> None :
235246 """Set the created and ttl of a record."""
236247 # It would be better if we made a copy instead of mutating the record
237248 # in place, but records currently don't have a copy method.
238249 self .created = created
239250 self .ttl = ttl
240251
241- def _display_fields (self ) -> list [tuple [str , str ]]:
242- remaining = int (self .get_remaining_ttl (current_time_millis ()))
243- return [* DNSEntry ._display_fields (self ), ("ttl" , f"{ self .ttl } ({ remaining } remaining)" )]
244-
245- def _repr_with (self , * details : tuple [str , str ]) -> str :
246- return _format_display (type (self ).__name__ , [* self ._display_fields (), * details ])
247-
248- def to_string (self , other : bytes | str ) -> str :
249- """Compatibility alias rendering through the display formatter."""
250- return self ._repr_with (("data" , str (other )))
251-
252252 def _suppressed_by_answer (self , answer : DNSRecord ) -> bool :
253- """True when the answer matches this record with at least half its TTL left ."""
253+ """RFC 6762 section 7.1 known answer test: an equal record whose TTL is at least half of ours ."""
254254 return self == answer and self .ttl / 2 < answer .ttl
255255
256256
@@ -618,17 +618,17 @@ def lookup_set(self) -> set[DNSRecord]:
618618 """Return the lookup table as aset."""
619619 return set (self ._get_lookup ())
620620
621- def _get_lookup (self ) -> dict [DNSRecord , DNSRecord ]:
622- """Return the lookup table, building it if needed."""
623- if self ._lookup is None :
624- # Build the hash table so we can lookup the record ttl
625- self ._lookup = {record : record for record in self ._records }
626- return self ._lookup
627-
628621 def suppresses (self , record : _DNSRecord ) -> bool :
629622 """True when the set holds a match with over half the record's TTL left."""
630623 lookup = self ._get_lookup ()
631624 other = lookup .get (record )
632625 if other is None :
633626 return False
634627 return other .ttl > (record .ttl / 2 )
628+
629+ def _get_lookup (self ) -> dict [DNSRecord , DNSRecord ]:
630+ """Return the lookup table, building it if needed."""
631+ if self ._lookup is None :
632+ # Build the hash table so we can lookup the record ttl
633+ self ._lookup = {record : record for record in self ._records }
634+ return self ._lookup
0 commit comments