Action de grace def

Comment

Author: Admin | 2025-04-28

# Copyright (C) Dnspython Contributors, see LICENSE for text of ISC license# Copyright (C) 2003-2017 Nominum, Inc.## Permission to use, copy, modify, and distribute this software and its# documentation for any purpose with or without fee is hereby granted,# provided that the above copyright notice and this permission notice# appear in all copies.## THE SOFTWARE IS PROVIDED "AS IS" AND NOMINUM DISCLAIMS ALL WARRANTIES# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NOMINUM BE LIABLE FOR# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE."""DNS stub resolver."""import contextlibimport randomimport socketimport sysimport threadingimport timeimport warningsfrom typing import Any, Dict, Iterator, List, Optional, Sequence, Tuple, Union, castfrom urllib.parse import urlparseimport dns._ddrimport dns.ednsimport dns.exceptionimport dns.flagsimport dns.inetimport dns.ipv4import dns.ipv6import dns.messageimport dns.nameimport dns.nameserverimport dns.queryimport dns.rcodeimport dns.rdataimport dns.rdataclassimport dns.rdatatypeimport dns.rdtypes.ANY.PTRimport dns.rdtypes.svcbbaseimport dns.reversenameimport dns.tsigif sys.platform == "win32": # pragma: no cover import dns.win32util[docs]class NXDOMAIN(dns.exception.DNSException): """The DNS query name does not exist.""" supp_kwargs = {"qnames", "responses"} fmt = None # we have our own __str__ implementation # pylint: disable=arguments-differ # We do this as otherwise mypy complains about unexpected keyword argument # idna_exception def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def _check_kwargs(self, qnames, responses=None): # pyright: ignore if not isinstance(qnames, (list, tuple, set)): raise AttributeError("qnames must be a list, tuple or set") if len(qnames) == 0: raise AttributeError("qnames must contain at least one element") if responses is None: responses = {} elif not isinstance(responses, dict): raise AttributeError("responses must be a dict(qname=response)") kwargs = dict(qnames=qnames, responses=responses) return kwargs def __str__(self) -> str: if "qnames" not in self.kwargs: return super().__str__() qnames = self.kwargs["qnames"] if len(qnames) > 1: msg = "None of DNS query names exist" else: msg = "The DNS query name does not exist" qnames = ", ".join(map(str, qnames)) return f"{msg}: {qnames}" @property def canonical_name(self): """Return the unresolved canonical name.""" if "qnames" not in self.kwargs: raise TypeError("parametrized exception required") for qname in self.kwargs["qnames"]: response = self.kwargs["responses"][qname] try: cname = response.canonical_name() if cname != qname: return cname except Exception: # pragma: no cover # We can just eat this exception as it means there was # something wrong with the response. pass return self.kwargs["qnames"][0] def __add__(self, e_nx): """Augment by results from another NXDOMAIN exception.""" qnames0 = list(self.kwargs.get("qnames",

Add Comment