]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
Include the text description of an EDE. (#1042)
authorBrian Wellington <bwelling@xbill.org>
Fri, 9 Feb 2024 02:02:39 +0000 (18:02 -0800)
committerGitHub <noreply@github.com>
Fri, 9 Feb 2024 02:02:39 +0000 (18:02 -0800)
* Include the text description of an EDE.

For known EDEs, add the description of the code in the output.

* Update test.

dns/edns.py
tests/test_edns.py

index b29afaa3bc0029436f13667cce4d6d54f2a18ffa..776e5eeba7b725ea68e2a1f3ffc7099b7797b709 100644 (file)
@@ -345,6 +345,8 @@ class EDECode(dns.enum.IntEnum):
 class EDEOption(Option):  # lgtm[py/missing-equals]
     """Extended DNS Error (EDE, RFC8914)"""
 
+    _preserve_case = {"DNSKEY", "DS", "DNSSEC", "RRSIGs", "NSEC", "NXDOMAIN"}
+
     def __init__(self, code: Union[EDECode, str], text: Optional[str] = None):
         """*code*, a ``dns.edns.EDECode`` or ``str``, the info code of the
         extended error.
@@ -362,6 +364,13 @@ class EDEOption(Option):  # lgtm[py/missing-equals]
 
     def to_text(self) -> str:
         output = f"EDE {self.code}"
+        if self.code in EDECode:
+            desc = EDECode.to_text(self.code)
+            desc = " ".join(
+                word if word in self._preserve_case else word.title()
+                for word in desc.split("_")
+            )
+            output += f" ({desc})"
         if self.text is not None:
             output += f": {self.text}"
         return output
index 98e468ba125cc7cee5f63f58797984f3c28d6cc4..367c723c6668c7cbc046478125730b51bd982202 100644 (file)
@@ -141,7 +141,7 @@ class OptionTestCase(unittest.TestCase):
         opt.to_wire(io)
         data = io.getvalue()
         self.assertEqual(data, b"\x00\x03")
-        self.assertEqual(str(opt), "EDE 3")
+        self.assertEqual(str(opt), "EDE 3 (Stale Answer)")
         # with text
         opt = dns.edns.EDEOption(16, "test")
         io = BytesIO()