MCPcopy Create free account
hub / github.com/rthalley/dnspython / NXDOMAIN

Class NXDOMAIN

dns/resolver.py:54–139  ·  view source on GitHub ↗

The DNS query name does not exist.

Source from the content-addressed store, hash-verified

52
53
54class NXDOMAIN(dns.exception.DNSException):
55 """The DNS query name does not exist."""
56
57 supp_kwargs = {"qnames", "responses"}
58 fmt = None # we have our own __str__ implementation
59
60 # pylint: disable=arguments-differ
61
62 # We do this as otherwise mypy complains about unexpected keyword argument
63 # idna_exception
64 def __init__(self, *args, **kwargs):
65 super().__init__(*args, **kwargs)
66
67 def _check_kwargs(self, qnames, responses=None): # pyright: ignore
68 if not isinstance(qnames, list | tuple | set):
69 raise AttributeError("qnames must be a list, tuple or set")
70 if len(qnames) == 0:
71 raise AttributeError("qnames must contain at least one element")
72 if responses is None:
73 responses = {}
74 elif not isinstance(responses, dict):
75 raise AttributeError("responses must be a dict(qname=response)")
76 kwargs = dict(qnames=qnames, responses=responses)
77 return kwargs
78
79 def __str__(self) -> str:
80 if "qnames" not in self.kwargs:
81 return super().__str__()
82 qnames = self.kwargs["qnames"]
83 if len(qnames) > 1:
84 msg = "None of DNS query names exist"
85 else:
86 msg = "The DNS query name does not exist"
87 qnames = ", ".join(map(str, qnames))
88 return f"{msg}: {qnames}"
89
90 @property
91 def canonical_name(self):
92 """Return the unresolved canonical name."""
93 if "qnames" not in self.kwargs:
94 raise TypeError("parametrized exception required")
95 for qname in self.kwargs["qnames"]:
96 response = self.kwargs["responses"][qname]
97 try:
98 cname = response.canonical_name()
99 if cname != qname:
100 return cname
101 except Exception: # pragma: no cover
102 # We can just eat this exception as it means there was
103 # something wrong with the response.
104 pass
105 return self.kwargs["qnames"][0]
106
107 def __add__(self, e_nx):
108 """Augment by results from another NXDOMAIN exception."""
109 qnames0 = list(self.kwargs.get("qnames", []))
110 responses0 = dict(self.kwargs.get("responses", {}))
111 responses1 = e_nx.kwargs.get("responses", {})

Callers 2

__add__Method · 0.85
next_requestMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…