U
    f                     @   s   d Z ddlmZm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
G dd dZdS )zCommon DNS Exceptions.

Dnspython modules may also define their own exceptions, which will
always be subclasses of ``DNSException``.
    )OptionalSetc                       sx   e Zd ZU dZdZee ed< e Z	e
e ed< dZee ed<  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.
    Nmsgsupp_kwargsfmtc                    sh   | j || |r*| jf || _t| | _nt | _| jd krD| j| _|rVt j|  nt | j d S N)	_check_params_check_kwargskwargsstrr   dict__doc__super__init__selfargsr   	__class__ [/home/www/findmeahotel.co.uk/times_travel/venv/lib/python3.8/site-packages/dns/exception.pyr   7   s    
zDNSException.__init__c                 O   s$   |s|r t |t |ks t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)boolAssertionErrorr   r   r   r   r	   G   s    zDNSException._check_paramsc                 K   s(   |r$t | | jks$td| j |S )Nz-following set of keyword args is required: %s)setkeysr   r   )r   r   r   r   r   r
   P   s    zDNSException._check_kwargsc                 K   sd   i }|  D ]R\}}t|ttfrVttt|||< t|| dkr^||  ||< q|||< q|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datar   r   r   _fmt_kwargsW   s    
zDNSException._fmt_kwargsc                    s6   | j r(| jr(| jf | j }| jjf |S t  S d S r   )r   r   r&   formatr   __str__)r   r#   r   r   r   r(   i   s    zDNSException.__str__)__name__
__module____qualname__r   r   r   r   __annotations__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.   s   s   r.   c                   @   s   e Zd ZdZdS )SyntaxErrorzText input is malformed.Nr/   r   r   r   r   r0   w   s   r0   c                   @   s   e Zd ZdZdS )UnexpectedEndzText input ended unexpectedly.Nr/   r   r   r   r   r1   {   s   r1   c                   @   s   e Zd ZdZdS )TooBigzThe DNS message is too big.Nr/   r   r   r   r   r2      s   r2   c                       s*   e Zd ZdZdhZdZ fddZ  ZS )TimeoutzThe DNS operation timed out.timeoutz7The DNS operation timed out after {timeout:.3f} secondsc                    s   t  j|| d S r   )r   r   r   r   r   r   r      s    zTimeout.__init__)r)   r*   r+   r   r   r   r   r-   r   r   r   r   r3      s   r3   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )ExceptionWrapperc                 C   s
   || _ d S r   )exception_class)r   r6   r   r   r   r      s    zExceptionWrapper.__init__c                 C   s   | S r   r   )r   r   r   r   	__enter__   s    zExceptionWrapper.__enter__c                 C   s(   |d k	r$t || js$| t||dS )NF)r   r6   r   )r   exc_typeexc_valexc_tbr   r   r   __exit__   s    zExceptionWrapper.__exit__N)r)   r*   r+   r   r7   r;   r   r   r   r   r5      s   r5   N)r   typingr   r   	Exceptionr   r.   r0   r1   r2   r3   r5   r   r   r   r   <module>   s   W