a MeE@sdZddlmZmZGdddeZGdddeZGdddeZGd d d eZGd d d eZ Gd ddeZ GdddeZ Gddde Z GdddeZ GdddeZGdddZdS)zCommon DNS Exceptions. Dnspython modules may also define their own exceptions, which will always be subclasses of ``DNSException``. )OptionalSetcsxeZdZUdZdZeeed<eZ e eed<dZ eeed<fddZ dd Z d d Zd d ZfddZZS) DNSExceptionaAbstract base class shared by all dnspython exceptions. It supports two basic modes of operation: a) Old/compatible mode is used if ``__init__`` was called with empty *kwargs*. In compatible mode all *args* are passed to the standard Python Exception class as before and all *args* are printed by the standard ``__str__`` implementation. Class variable ``msg`` (or doc string if ``msg`` is ``None``) is returned from ``str()`` if *args* is empty. b) New/parametrized mode is used if ``__init__`` was called with non-empty *kwargs*. In the new mode *args* must be empty and all kwargs must match those set in class variable ``supp_kwargs``. All kwargs are stored inside ``self.kwargs`` and used in a new ``__str__`` implementation to construct a formatted message based on the ``fmt`` class variable, a ``string``. In the simplest case it is enough to override the ``supp_kwargs`` and ``fmt`` class variables to get nice parametrized messages. Nmsg supp_kwargsfmtcsp|j|i||r2|jfi||_t||_nt|_|jdurL|j|_|r^tj|nt|jdSN) _check_params _check_kwargskwargsstrrdict__doc__super__init__selfargsr  __class__1/usr/lib/python3.9/site-packages/dns/exception.pyr7s  zDNSException.__init__cOs |s|rdS)zsOld exceptions supported only args and not kwargs. For sanity we do not allow to mix old and new behavior.Nrrrrrr GszDNSException._check_paramscKs|r|Srr)rr rrrr PszDNSException._check_kwargscKsdi}|D]R\}}t|ttfrVttt|||<t||dkr^||||<q |||<q |S)zFormat kwargs before printing them. Resulting dictionary has to have keys necessary for str.format call on fmt class variable. )items isinstancelistsetmapr lenpop)rr fmtargskwdatarrr _fmt_kwargsWs zDNSException._fmt_kwargscs>|jr0|jr0|jfi|j}|jjfi|StSdSr)r rr#formatr__str__)rr rrrr%is zDNSException.__str__)__name__ __module__ __qualname__rrrr __annotations__rrrrrr r r#r% __classcell__rrrrrs   rc@seZdZdZdS) FormErrorzDNS message is malformed.Nr&r'r(rrrrrr+ssr+c@seZdZdZdS) SyntaxErrorzText input is malformed.Nr,rrrrr-wsr-c@seZdZdZdS) UnexpectedEndzText input ended unexpectedly.Nr,rrrrr.{sr.c@seZdZdZdS)TooBigzThe DNS message is too big.Nr,rrrrr/sr/cs*eZdZdZdhZdZfddZZS)TimeoutzThe DNS operation timed out.timeoutz7The DNS operation timed out after {timeout:.3f} secondscstj|i|dSr)rrrrrrrszTimeout.__init__)r&r'r(rrrrr*rrrrr0sr0c@seZdZdZdS)UnsupportedAlgorithmz&The DNSSEC algorithm is not supported.Nr,rrrrr2sr2c@seZdZdZdS)AlgorithmKeyMismatchz=The DNSSEC algorithm is not supported for the given key type.Nr,rrrrr3sr3c@seZdZdZdS)ValidationFailurez The DNSSEC signature is invalid.Nr,rrrrr4sr4c@seZdZdZdS)DeniedByPolicyzDenied by DNSSEC policy.Nr,rrrrr5sr5c@s$eZdZddZddZddZdS)ExceptionWrappercCs ||_dSr)exception_class)rr7rrrrszExceptionWrapper.__init__cCs|Srr)rrrr __enter__szExceptionWrapper.__enter__cCs(|dur$t||js$|t||dS)NF)rr7r )rexc_typeZexc_valZexc_tbrrr__exit__szExceptionWrapper.__exit__N)r&r'r(rr8r:rrrrr6sr6N)rtypingrr Exceptionrr+r-r.r/r0r2r3r4r5r6rrrrsW