@@ -44,7 +44,9 @@ def _class_label(class_: int) -> str:
4444 return _CLASSES .get (class_ , f"unknown-class-{ class_ } " )
4545
4646
47- def _format_display (kind : str , fields : list [tuple [str , str ]]) -> str :
47+ def _format_display (kind : str , fields : list [tuple [str , str ]], data : bytes | str | None = None ) -> str :
48+ if data is not None :
49+ fields = [* fields , ("data" , str (data ))]
4850 body = " " .join ([f"{ key } ={ value } " if key else value for key , value in fields ])
4951 return f"<{ kind } { body } >"
5052
@@ -83,12 +85,9 @@ def class_label(self) -> str:
8385 """Human readable label for the record class."""
8486 return _class_label (self .class_ )
8587
86- def entry_to_string (self , hdr : str , other : bytes | str | None ) -> str :
87- """Compatibility alias rendering through the display formatter."""
88- fields = self ._display_fields ()
89- if other is not None :
90- fields .append (("data" , str (other )))
91- return _format_display (hdr , fields )
88+ def entry_to_string (self , kind : str , extra : bytes | str | None ) -> str :
89+ """Compatibility alias for the display formatter."""
90+ return _format_display (kind , self ._display_fields (), extra )
9291
9392 @staticmethod
9493 def get_class_ (class_ : int ) -> str :
@@ -221,8 +220,8 @@ def suppressed_by(self, msg: DNSIncoming) -> bool:
221220 return False
222221
223222 def to_string (self , other : bytes | str ) -> str :
224- """Compatibility alias rendering through the display formatter."""
225- return self . _repr_with (( "data" , str ( other )) )
223+ """Compatibility alias for the display formatter."""
224+ return _format_display ( type ( self ). __name__ , self . _display_fields (), other )
226225
227226 def write (self , out : DNSOutgoing ) -> None :
228227 raise AbstractMethodException (f"{ type (self ).__name__ } is missing write" )
0 commit comments