a
    sd_Ö  ã                   @   sh   d Z G dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZG d	d
„ d
eƒZG dd„ deƒZdS )z…Common DNS Exceptions.

Dnspython modules may also define their own exceptions, which will
always be subclasses of ``DNSException``.
c                       sR   e Zd ZdZdZeƒ ZdZ‡ fdd„Zdd„ Z	dd„ Z
d	d
„ Z‡ fd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 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.
    Nc                    sp   | j |i |¤Ž |r2| jf i |¤Ž| _t| ƒ| _ntƒ | _| jd u rL| j| _|r^tƒ j|Ž  ntƒ  | j¡ d S ©N)	Ú_check_paramsÚ_check_kwargsÚkwargsÚstrÚmsgÚdictÚ__doc__ÚsuperÚ__init__©ÚselfÚargsr   ©Ú	__class__© ú//usr/lib/python3/dist-packages/dns/exception.pyr   3   s    
zDNSException.__init__c                 O   s$   |s|r t |ƒt |ƒks J dƒ‚dS )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)Úboolr   r   r   r   r   B   s    ÿzDNSException._check_paramsc                 K   s(   |r$t | ¡ ƒ| jks$J d| j ƒ‚|S )Nz-following set of keyword args is required: %s)ÚsetÚkeysÚsupp_kwargs)r   r   r   r   r   r   J   s    ÿÿzDNSException._check_kwargsc                 K   sd   i }|  ¡ D ]R\}}t|ttfƒrVttt|ƒƒ||< t|| ƒdkr^||  ¡ ||< q|||< q|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Údatar   r   r   Ú_fmt_kwargsQ   s    
zDNSException._fmt_kwargsc                    s>   | j r0| jr0| jf i | j ¤Ž}| jjf i |¤ŽS tƒ  ¡ S d S r   )r   Úfmtr!   Úformatr
   Ú__str__)r   r   r   r   r   r$   c   s    zDNSException.__str__)Ú__name__Ú
__module__Ú__qualname__r	   r   r   r   r"   r   r   r   r!   r$   Ú__classcell__r   r   r   r   r      s   r   c                   @   s   e Zd ZdZdS )Ú	FormErrorzDNS message is malformed.N©r%   r&   r'   r	   r   r   r   r   r)   m   s   r)   c                   @   s   e Zd ZdZdS )ÚSyntaxErrorzText input is malformed.Nr*   r   r   r   r   r+   q   s   r+   c                   @   s   e Zd ZdZdS )ÚUnexpectedEndzText input ended unexpectedly.Nr*   r   r   r   r   r,   u   s   r,   c                   @   s   e Zd ZdZdS )ÚTooBigzThe DNS message is too big.Nr*   r   r   r   r   r-   y   s   r-   c                   @   s   e Zd ZdZdhZdZdS )ÚTimeoutzThe DNS operation timed out.Ztimeoutz3The DNS operation timed out after {timeout} secondsN)r%   r&   r'   r	   r   r"   r   r   r   r   r.   }   s   r.   N)r	   Ú	Exceptionr   r)   r+   r,   r-   r.   r   r   r   r   Ú<module>   s   U