U
    <æ{fE  ã                   @   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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 )z…Common 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__© úL/var/www/html/Darija-Ai-API/env/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 )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_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ZdS )ÚUnsupportedAlgorithmz&The DNSSEC algorithm is not supported.Nr/   r   r   r   r   r5      s   r5   c                   @   s   e Zd ZdZdS )ÚAlgorithmKeyMismatchz=The DNSSEC algorithm is not supported for the given key type.Nr/   r   r   r   r   r6   “   s   r6   c                   @   s   e Zd ZdZdS )ÚValidationFailurez The DNSSEC signature is invalid.Nr/   r   r   r   r   r7   —   s   r7   c                   @   s   e Zd ZdZdS )ÚDeniedByPolicyzDenied by DNSSEC policy.Nr/   r   r   r   r   r8   ›   s   r8   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   r:   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   r:   r   )r   Úexc_typeÚexc_valÚexc_tbr   r   r   Ú__exit__¦   s    zExceptionWrapper.__exit__N)r)   r*   r+   r   r;   r?   r   r   r   r   r9   Ÿ   s   r9   N)r   Útypingr   r   Ú	Exceptionr   r.   r0   r1   r2   r3   r5   r6   r7   r8   r9   r   r   r   r   Ú<module>   s   W