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|r t|t|ks JddS)zsOld exceptions supported only args and not kwargs. For sanity we do not allow to mix old and new behavior.z=keyword arguments are mutually exclusive with positional argsN)boolrrrrr Gs zDNSException._check_paramscKs(|r$t||jks$Jd|j|S)Nz-following set of keyword args is required: %s)setkeysr)rr rrrr Ps zDNSException._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 isinstancelistrmapr 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.rrrrr0{sr0c@seZdZdZdS)TooBigzThe DNS message is too big.Nr.rrrrr1sr1cs*eZdZdZdhZdZfddZZS)TimeoutzThe DNS operation timed out.timeoutz7The DNS operation timed out after {timeout:.3f} secondscstj|i|dSr)rrrrrrrszTimeout.__init__)r(r)r*rrrrr,rrrrr2sr2c@seZdZdZdS)UnsupportedAlgorithmz&The DNSSEC algorithm is not supported.Nr.rrrrr4sr4c@seZdZdZdS)AlgorithmKeyMismatchz=The DNSSEC algorithm is not supported for the given key type.Nr.rrrrr5sr5c@seZdZdZdS)ValidationFailurez The DNSSEC signature is invalid.Nr.rrrrr6sr6c@seZdZdZdS)DeniedByPolicyzDenied by DNSSEC policy.Nr.rrrrr7sr7c@s$eZdZddZddZddZdS)ExceptionWrappercCs ||_dSr)exception_class)rr9rrrrszExceptionWrapper.__init__cCs|Srr)rrrr __enter__szExceptionWrapper.__enter__cCs(|dur$t||js$|t||dS)NF)rr9r )rexc_typeZexc_valZexc_tbrrr__exit__szExceptionWrapper.__exit__N)r(r)r*rr:r<rrrrr8sr8N)rtypingrr Exceptionrr-r/r0r1r2r4r5r6r7r8rrrrsW