
                             d Z  G d de      Z G d de      Z G d de      Z G d de      Z G d	 d
e      Z G d de      Zy)zCommon DNS Exceptions.

Dnspython modules may also define their own exceptions, which will
always be subclasses of ``DNSException``.
c                   T     e Zd ZdZdZ e       ZdZ fdZd Z	d Z
d Z fdZ x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                 6    | j                   |i | |r( | j                  di || _        t        |       | _        nt               | _        | j                  | j                  | _        |rt        t        | &  |  y t        t        | '  | j                         y N )
_check_params_check_kwargskwargsstrmsgdict__doc__superr   __init__)selfargsr	   	__class__s       lib/third_party/dns/exception.pyr   zDNSException.__init__3   s    D+F+,$,,6v6DK4yDH&DK88||DH,.5,.txx8    c                 J    |s|rt        |      t        |      k7  sJ d       yy)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)r   r   r	   s      r   r   zDNSException._check_paramsB   s0     6:f- POP- r   c                 ~    |r:t        |j                               | j                  k(  sJ d| j                  z         |S )Nz-following set of keyword args is required: %s)setkeyssupp_kwargs)r   r	   s     r   r   zDNSException._check_kwargsJ   sC    v{{}%)9)99 &?$$&&9 r   c                     i }|j                         D ]e  \  }}t        |t        t        f      rEt        t	        t
        |            ||<   t        ||         dk(  sJ||   j                         ||<   a|||<   g |S )zFormat 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datas        r   _fmt_kwargszDNSException._fmt_kwargsQ   st     HB$s,"3sD>2wr{#q(")"+//"3GBK" ' r   c                     | j                   rD| j                  r8 | j                  di | j                   } | j                  j                  di |S t        t
        |          S r   )r	   fmtr&   formatr   r   __str__)r   r#   r   s     r   r*   zDNSException.__str__c   sS    ;;488&d&&55G"488??-W-- t466r   )__name__
__module____qualname__r   r   r   r   r(   r   r   r   r&   r*   __classcell__)r   s   @r   r   r      s:    , C%K
C9P$7 7r   r   c                       e Zd ZdZy)	FormErrorzDNS message is malformed.Nr+   r,   r-   r   r   r   r   r0   r0   m   s    #r   r0   c                       e Zd ZdZy)SyntaxErrorzText input is malformed.Nr1   r   r   r   r3   r3   q   s    "r   r3   c                       e Zd ZdZy)UnexpectedEndzText input ended unexpectedly.Nr1   r   r   r   r5   r5   u   s    (r   r5   c                       e Zd ZdZy)TooBigzThe DNS message is too big.Nr1   r   r   r   r7   r7   y   s    %r   r7   c                       e Zd ZdZdhZdZy)TimeoutzThe DNS operation timed out.timeoutz3The DNS operation timed out after {timeout} secondsN)r+   r,   r-   r   r   r(   r   r   r   r9   r9   }   s    &+K
?Cr   r9   N)r   	Exceptionr   r0   r3   r5   r7   r9   r   r   r   <module>r<      sW   $R79 R7j$ $#, #)K )&\ &@l @r   