a
    PҚ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                    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strr   dict__doc__super__init__selfargsr   	__class__ H/wd/webapps/venvs/v2025_4um/lib/python3.9/site-packages/dns/exception.pyr   7   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	   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 ]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                    s>   | j r0| jr0| jf i | j }| jjf i |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   r/   w   s   r/   c                   @   s   e Zd ZdZdS )UnexpectedEndzText input ended unexpectedly.Nr.   r   r   r   r   r0   {   s   r0   c                   @   s   e Zd ZdZdS )TooBigzThe DNS message is too big.Nr.   r   r   r   r   r1      s   r1   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 r   )r   r   r   r   r   r   r      s    zTimeout.__init__)r(   r)   r*   r   r   r   r   r,   r   r   r   r   r2      s   r2   c                   @   s   e Zd ZdZdS )UnsupportedAlgorithmz&The DNSSEC algorithm is not supported.Nr.   r   r   r   r   r4      s   r4   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   r5      s   r5   c                   @   s   e Zd ZdZdS )ValidationFailurez The DNSSEC signature is invalid.Nr.   r   r   r   r   r6      s   r6   c                   @   s   e Zd ZdZdS )DeniedByPolicyzDenied by DNSSEC policy.Nr.   r   r   r   r   r7      s   r7   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   r9   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 ur$t || js$| t||dS )NF)r   r9   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   r8      s   r8   N)r   typingr   r   	Exceptionr   r-   r/   r0   r1   r2   r4   r5   r6   r7   r8   r   r   r   r   <module>   s   W