U mfE@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_kwargsfmtcsh|j|||r*|jf||_t||_nt|_|jdkrD|j|_|rVtj|nt|jdSN) _check_params _check_kwargskwargsstrrdict__doc__super__init__selfargsr  __class__;/opt/hc_python/lib/python3.8/site-packages/dns/exception.pyr7s   zDNSException.__init__cOs$|s|r t|t|ks tddS)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)boolAssertionErrorrrrrr Gs zDNSException._check_paramscKs(|r$t||jks$td|j|S)Nz-following set of keyword args is required: %s)setkeysrr)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_kwargscs6|jr(|jr(|jf|j}|jjf|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/rrrrr0wsr0c@seZdZdZdS) UnexpectedEndzText input ended unexpectedly.Nr/rrrrr1{sr1c@seZdZdZdS)TooBigzThe DNS message is too big.Nr/rrrrr2sr2cs*eZdZdZdhZdZfddZZS)TimeoutzThe DNS operation timed out.timeoutz7The DNS operation timed out after {timeout:.3f} secondscstj||dSr)rrrrrrrszTimeout.__init__)r)r*r+rrrrr-rrrrr3sr3c@seZdZdZdS)UnsupportedAlgorithmz&The DNSSEC algorithm is not supported.Nr/rrrrr5sr5c@seZdZdZdS)AlgorithmKeyMismatchz=The DNSSEC algorithm is not supported for the given key type.Nr/rrrrr6sr6c@seZdZdZdS)ValidationFailurez The DNSSEC signature is invalid.Nr/rrrrr7sr7c@seZdZdZdS)DeniedByPolicyzDenied by DNSSEC policy.Nr/rrrrr8sr8c@s$eZdZddZddZddZdS)ExceptionWrappercCs ||_dSr)exception_class)rr:rrrrszExceptionWrapper.__init__cCs|Srr)rrrr __enter__szExceptionWrapper.__enter__cCs(|dk r$t||js$|t||dS)NF)rr:r )rexc_typeexc_valexc_tbrrr__exit__szExceptionWrapper.__exit__N)r)r*r+rr;r?rrrrr9sr9N)rtypingrr Exceptionrr.r0r1r2r3r5r6r7r8r9rrrrsW