summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Halley <halley@dnspython.org>2021-12-19 12:00:29 -0800
committerBob Halley <halley@dnspython.org>2021-12-19 12:05:06 -0800
commit701169f45853cc7651a680a979679d046db409aa (patch)
treefa35a103b63b723e66b3f8a412299187d5493008
parent0f1d40bb72942ec6785d18128723972d70e5b620 (diff)
downloaddnspython-701169f45853cc7651a680a979679d046db409aa.tar.gz
add dns.edns.EDECode enum
-rw-r--r--dns/edns.py46
-rw-r--r--doc/whatsnew.rst2
-rw-r--r--tests/test_constants.py3
3 files changed, 43 insertions, 8 deletions
diff --git a/dns/edns.py b/dns/edns.py
index 5d85da9..9d7e909 100644
--- a/dns/edns.py
+++ b/dns/edns.py
@@ -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):
diff --git a/doc/whatsnew.rst b/doc/whatsnew.rst
index fcb8e89..b9dc13b 100644
--- a/doc/whatsnew.rst
+++ b/doc/whatsnew.rst
@@ -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.
diff --git a/tests/test_constants.py b/tests/test_constants.py
index e818bb9..0c38c28 100644
--- a/tests/test_constants.py
+++ b/tests/test_constants.py
@@ -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})