o
    hA                     @   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 )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                    sr   | j |i | |r| jdi || _t| | _nt | _| jd u r&| j| _|r0t j|  d S t | j d S N )	_check_params_check_kwargskwargsstrr   dict__doc__super__init__selfargsr   	__class__r	   @/var/www/html/venv/lib/python3.10/site-packages/dns/exception.pyr   7   s   
zDNSException.__init__c                 O   s(   |s|rt |t |ksJ ddS 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
   G   s   zDNSException._check_paramsc                 K   s*   |rt | | jksJ d| j |S )Nz+following set of keyword args is required: )setkeysr   )r   r   r	   r	   r   r   P   s
   
zDNSException._check_kwargsc                 K   sd   i }|  D ])\}}t|ttfr+t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                    s:   | j r| jr| jdi | j }| jjdi |S t  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                   @      e Zd ZdZdS )	FormErrorzDNS message is malformed.Nr(   r)   r*   r   r	   r	   r	   r   r.   s       r.   c                   @   r-   )SyntaxErrorzText input is malformed.Nr/   r	   r	   r	   r   r1   w   r0   r1   c                   @   r-   )UnexpectedEndzText input ended unexpectedly.Nr/   r	   r	   r	   r   r2   {   r0   r2   c                   @   r-   )TooBigzThe DNS message is too big.Nr/   r	   r	   r	   r   r3      r0   r3   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|i | d S N)r   r   r   r   r	   r   r      s   zTimeout.__init__)r(   r)   r*   r   r   r   r   r,   r	   r	   r   r   r4      s
    r4   c                   @   r-   )UnsupportedAlgorithmz&The DNSSEC algorithm is not supported.Nr/   r	   r	   r	   r   r7      r0   r7   c                   @   r-   )AlgorithmKeyMismatchz=The DNSSEC algorithm is not supported for the given key type.Nr/   r	   r	   r	   r   r8      r0   r8   c                   @   r-   )ValidationFailurez The DNSSEC signature is invalid.Nr/   r	   r	   r	   r   r9      r0   r9   c                   @   r-   )DeniedByPolicyzDenied by DNSSEC policy.Nr/   r	   r	   r	   r   r:      r0   r:   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )ExceptionWrapperc                 C   s
   || _ d S r6   )exception_class)r   r<   r	   r	   r   r      s   
zExceptionWrapper.__init__c                 C   s   | S r6   r	   )r   r	   r	   r   	__enter__   s   zExceptionWrapper.__enter__c                 C   s(   |d u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=   rA   r	   r	   r	   r   r;      s    r;   N)r   typingr   r   	Exceptionr   r.   r1   r2   r3   r4   r7   r8   r9   r:   r;   r	   r	   r	   r   <module>   s   W