]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
add dns.edns.EDECode enum
authorBob Halley <halley@dnspython.org>
Sun, 19 Dec 2021 20:00:29 +0000 (12:00 -0800)
committerBob Halley <halley@dnspython.org>
Sun, 19 Dec 2021 20:05:06 +0000 (12:05 -0800)
dns/edns.py
doc/whatsnew.rst
tests/test_constants.py

index 5d85da9b65cba87bfffd539a29f26dbe83ff7f55..9d7e909dbbe767ad905f7e240dfb24c6c77060d0 100644 (file)
@@ -302,20 +302,52 @@ class ECSOption(Option):
         return cls(addr, src, scope)
 
 
+class EDECode(dns.enum.IntEnum):
+    OTHER = 0
+    UNSUPPORTED_DNSKEY_ALGORITHM = 1
+    UNSUPPORTED_DS_DIGEST_TYPE = 2
+    STALE_ANSWER = 3
+    FORGED_ANSWER = 4
+    DNSSEC_INDETERMINATE = 5
+    DNSSEC_BOGUS = 6
+    SIGNATURE_EXPIRED = 7
+    SIGNATURE_NOT_YET_VALID = 8
+    DNSKEY_MISSING = 9
+    RRSIGS_MISSING = 10
+    NO_ZONE_KEY_BIT_SET = 11
+    NSEC_MISSING = 12
+    CACHED_ERROR = 13
+    NOT_READY = 14
+    BLOCKED = 15
+    CENSORED = 16
+    FILTERED = 17
+    PROHIBITED = 18
+    STALE_NXDOMAIN_ANSWER = 19
+    NOT_AUTHORITATIVE = 20
+    NOT_SUPPORTED = 21
+    NO_REACHABLE_AUTHORITY = 22
+    NETWORK_ERROR = 23
+    INVALID_DATA = 24
+
+    @classmethod
+    def _maximum(cls):
+        return 65535
+
+
 class EDEOption(Option):
     """Extended DNS Error (EDE, RFC8914)"""
 
     def __init__(self, code, text=None):
-        """*code*, an ``int``, the info code of the extended error.
+        """*code*, a ``dns.edns.EDECode`` or ``str``, the info code of the
+        extended error.
 
-        *text*, a ``str``, optional field containing additional textual
-        information.
+        *text*, a ``str`` or ``None``, specifying additional information about
+        the error.
         """
 
         super().__init__(OptionType.EDE)
 
-        if code < 0 or code > 65535:
-            raise ValueError('code must be uint16')
+        self.code = EDECode.make(code)
         if text is not None and not isinstance(text, str):
             raise ValueError('text must be string or None')
 
@@ -323,9 +355,9 @@ class EDEOption(Option):
         self.text = text
 
     def to_text(self):
-        output = "EDE {}".format(self.code)
+        output = f'EDE {self.code}'
         if self.text is not None:
-            output += ': {}'.format(self.text)
+            output += f': {self.text}'
         return output
 
     def to_wire(self, file=None):
index fcb8e8944c1d93b34840effa31144cb88457ad32..b9dc13bed25175ac40b3885344944340f76555a1 100644 (file)
@@ -44,6 +44,8 @@ What's New in dnspython
   Likewise if you have a node containing an MX rdataset and add a
   CNAME rdataset, the MX rdataset will be deleted.
 
+* Extended DNS Errors, as specified in RFC 8914, are now supported.
+
 See the `2.2 project <https://github.com/rthalley/dnspython/projects/4>`_ on
 github or the git change log for more details.
 
index e818bb9bcf0586abba9744a9069aadc2ba6f85a6..0c38c281f2b3e1a395a786a3a3403a57eff48b36 100644 (file)
@@ -35,4 +35,5 @@ class ConstantsTestCase(unittest.TestCase):
         tests.util.check_enum_exports(dns.rdatatype, self.assertEqual)
 
     def test_edns_constants(self):
-        tests.util.check_enum_exports(dns.edns, self.assertEqual)
+        tests.util.check_enum_exports(dns.edns, self.assertEqual,
+                                      only={dns.edns.OptionType})