3 dŠáWã@shdZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGd d „d eƒZGd d „d eƒZd S)zCommon DNS Exceptions.csReZdZdZdZeƒZdZ‡fdd„Zdd„Z dd„Z d d „Z ‡fd d „Z ‡Z S) Ú DNSExceptiona¡Abstract 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 standard Python Exception class as before and all *args are printed by 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 has to be empty and all kwargs has to exactly match set in class variable self.supp_kwargs. All kwargs are stored inside self.kwargs and used in new __str__ implementation to construct formatted message based on self.fmt string. In the simplest case it is enough to override supp_kwargs and fmt class variables to get nice parametrized messages. Ncsp|j||Ž|r*|jf|Ž|_t|ƒ|_ntƒ|_|jdkrD|j|_|rZtt|ƒj |Žntt|ƒj |jƒdS)N) Ú _check_paramsÚ _check_kwargsÚkwargsÚstrÚmsgÚdictÚ__doc__ÚsuperrÚ__init__)ÚselfÚargsr)Ú __class__©ú/usr/lib/python3.6/exception.pyr .s   zDNSException.__init__cOs$|s|r t|ƒt|ƒks tdƒ‚dS)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)ÚboolÚAssertionError)r r rrrrr=szDNSException._check_paramscKs(|r$t|jƒƒ|jks$td|jƒ‚|S)Nz-following set of keyword args is required: %s)ÚsetÚkeysÚ supp_kwargsr)r rrrrrEs  zDNSException._check_kwargscKshi}x^|jƒD]R\}}t|ttfƒrXttt|ƒƒ||<t||ƒdkr`||jƒ||<q|||<qW|S)z˜Format kwargs before printing them. Resulting dictionary has to have keys necessary for str.format call on fmt class variable. é)ÚitemsÚ isinstanceÚlistrÚmaprÚlenÚpop)r rÚfmtargsÚkwÚdatarrrÚ _fmt_kwargsLs zDNSException._fmt_kwargscs:|jr(|jr(|jf|jŽ}|jjf|ŽStt|ƒjƒSdS)N)rÚfmtrÚformatr rÚ__str__)r r)r rrr"^s zDNSException.__str__)Ú__name__Ú __module__Ú __qualname__rrrrr r rrrr"Ú __classcell__rr)r rrs rc@seZdZdZdS)Ú FormErrorzDNS message is malformed.N)r#r$r%rrrrrr'hsr'c@seZdZdZdS)Ú SyntaxErrorzText input is malformed.N)r#r$r%rrrrrr(msr(c@seZdZdZdS)Ú UnexpectedEndzText input ended unexpectedly.N)r#r$r%rrrrrr)rsr)c@seZdZdZdS)ÚTooBigzThe DNS message is too big.N)r#r$r%rrrrrr*wsr*c@seZdZdZedgƒZdZdS)ÚTimeoutzThe DNS operation timed out.Ztimeoutz3The DNS operation timed out after {timeout} secondsN)r#r$r%rrrr rrrrr+|s r+N)rÚ Exceptionrr'r(r)r*r+rrrrÚs U