
    MhNN                     h   d Z ddlZddlZddlmZ ddlmZ ddlmZmZ ddl	m
Z
mZmZmZ ddlmZ dd	lmZ g d
Zd Zd Zed             Z eddd           G d d                      Zd Z eddd           G d d                      Zd=dZ eddd           G d d                      Zd Z eddd           G d d                      Zd Z eddd           G d d                      Zd  Z eddd           G d! d"                      Z d>d#Z! eddd           G d$ d%                      Z"d>d&Z# eddd           G d' d(                      Z$d) Z%d* Z&d+ Z'd, Z( eddd           G d- d.                      Z)d/ Z* eddd           G d0 d1                      Z+d2 Z, eddd           G d3 d4                      Z-d5 Z. eddd           G d6 d7                      Z/de0e1fd8d9Z2 eddd           G d: d;                      Z3d< Z4dS )?z
Commonly useful validators.
    N)contextmanager)Pattern   )get_run_validatorsset_run_validators)_AndValidatorand_attribattrs)default_if_none)NotCallableError)r	   deep_iterabledeep_mappingdisabledgeget_disabledgtin_instance_ofis_callablelelt
matches_remax_lenmin_lennot_optionalor_set_disabledc                 &    t          |             dS )a  
    Globally disable or enable running validators.

    By default, they are run.

    Args:
        disabled (bool): If `True`, disable running all validators.

    .. warning::

        This function is not thread-safe!

    .. versionadded:: 21.3.0
    Nr   )r   s    O/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/attr/validators.pyr   r   *   s     8|$$$$$    c                       t                       S )z
    Return a bool indicating whether validators are currently disabled or not.

    Returns:
        bool:`True` if validators are currently disabled.

    .. versionadded:: 21.3.0
    )r    r#   r"   r   r   <   s     "####r#   c               #   x   K   t          d           	 dV  t          d           dS # t          d           w xY w)z
    Context manager that disables running validators within its context.

    .. warning::

        This context manager is not thread-safe!

    .. versionadded:: 21.3.0
    FNTr!   r%   r#   r"   r   r   H   sM       u!4     4    s   ( 9FT)reprslotsunsafe_hashc                   .    e Zd Z e            Zd Zd ZdS )_InstanceOfValidatorc           	          t          || j                  s5d|j         d| j        d|d|j        d	}t	          ||| j        |          dS )P
        We use a callable class to be able to change the ``__repr__``.
        '
' must be  (got z that is a ).N)
isinstancetypename	__class__	TypeErrorselfinstattrvaluemsgs        r"   __call__z_InstanceOfValidator.__call__^   sr     %++ 	gdigg49ggeggRWRagggC		  	 	r#   c                     d| j         dS )Nz <instance_of validator for type >r3   r8   s    r"   __repr__z_InstanceOfValidator.__repr__k       @$)@@@@r#   N__name__
__module____qualname__r
   r3   r=   rB   r%   r#   r"   r+   r+   Z   B        688D  A A A A Ar#   r+   c                      t          |           S )a  
    A validator that raises a `TypeError` if the initializer is called with a
    wrong type for this particular attribute (checks are performed using
    `isinstance` therefore it's also valid to pass a tuple of types).

    Args:
        type (type | tuple[type]): The type to check for.

    Raises:
        TypeError:
            With a human readable error message, the attribute (of type
            `attrs.Attribute`), the expected type, and the value it got.
    )r+   r@   s    r"   r   r   o         %%%r#   )r'   frozenr(   c                   B    e Zd Z e            Z e            Zd Zd ZdS )_MatchesReValidatorc                     |                      |          s2d|j         d| j        j        d|d}t          ||| j        |          dS )r-   r.   z' must match regex z (z	 doesn't)N)
match_funcr4   pattern
ValueErrorr7   s        r"   r=   z_MatchesReValidator.__call__   si     u%% 	`di``DL4H``e```C	  	 	r#   c                     d| j         dS )Nz"<matches_re validator for pattern r?   )rP   rA   s    r"   rB   z_MatchesReValidator.__repr__   s    EDLEEEEr#   N)rE   rF   rG   r
   rP   rO   r=   rB   r%   r#   r"   rM   rM      sM        fhhGJ  F F F F Fr#   rM   c           
         t           j        dt           j        t           j        f}||vr[d                    d                    t          d t          |          D                                           }t          |          t          | t                    r|rd}t          |          | }nt          j        | |          }|t           j        u r|j        }n|t           j        u r|j        }n|j        }t          ||          S )a  
    A validator that raises `ValueError` if the initializer is called with a
    string that doesn't match *regex*.

    Args:
        regex (str, re.Pattern):
            A regex string or precompiled pattern to match against

        flags (int):
            Flags that will be passed to the underlying re function (default 0)

        func (typing.Callable):
            Which underlying `re` function to call. Valid options are
            `re.fullmatch`, `re.search`, and `re.match`; the default `None`
            means `re.fullmatch`. For performance reasons, the pattern is
            always precompiled using `re.compile`.

    .. versionadded:: 19.2.0
    .. versionchanged:: 21.3.0 *regex* can be a pre-compiled pattern.
    Nz'func' must be one of {}.z, c              3   ,   K   | ]}|r|j         pd V  dS )NoneN)rE   ).0es     r"   	<genexpr>zmatches_re.<locals>.<genexpr>   s.      NN(aj3VNNNNNNr#   zR'flags' can only be used with a string pattern; pass flags to re.compile() instead)re	fullmatchsearchmatchformatjoinsortedsetrQ   r2   r   r6   compilerM   )regexflagsfuncvalid_funcsr<   rP   rO   s          r"   r   r      s    * <ry"(;K;)00IINNS=M=MNNNNN 
 

 oo%!! + 	!fCC.. *UE**rx]

			^

&
w
333r#   c                   .    e Zd Z e            Zd Zd ZdS )_OptionalValidatorc                 <    |d S |                      |||           d S N	validatorr8   r9   r:   r;   s       r"   r=   z_OptionalValidator.__call__   s(    =FtT5)))))r#   c                     d| j         dS )Nz<optional validator for z	 or None>rj   rA   s    r"   rB   z_OptionalValidator.__repr__   s    E$.EEEEr#   N)rE   rF   rG   r
   rk   r=   rB   r%   r#   r"   rg   rg      sB        I* * *F F F F Fr#   rg   c                     t          | t          t          f          rt          t	          |                     S t          |           S )a&  
    A validator that makes an attribute optional.  An optional attribute is one
    which can be set to `None` in addition to satisfying the requirements of
    the sub-validator.

    Args:
        validator
            (typing.Callable | tuple[typing.Callable] | list[typing.Callable]):
            A validator (or validators) that is used for non-`None` values.

    .. versionadded:: 15.1.0
    .. versionchanged:: 17.1.0 *validator* can be a list of validators.
    .. versionchanged:: 23.1.0 *validator* can also be a tuple of validators.
    )r2   listtuplerg   r   rj   s    r"   r   r      s>     )dE]++ <!-	":":;;;i(((r#   c                   F    e Zd Z e            Z ed          Zd Zd ZdS )_InValidatorF)hashc                     	 || j         v }n# t          $ r d}Y nw xY w|s-d|j         d| j        d|d}t	          ||| j        |          d S )NFr.   z' must be in r0   ))optionsr6   r4   _original_optionsrQ   )r8   r9   r:   r;   
in_optionsr<   s         r"   r=   z_InValidator.__call__   s    	$,.JJ 	 	 	JJJ	  	XdiXXd.DXXeXXXC&	  	 	s   	 c                     d| j         dS )Nz<in_ validator with options r?   )rw   rA   s    r"   rB   z_InValidator.__repr__   s    Id.DIIIIr#   N)rE   rF   rG   r
   rv   rw   r=   rB   r%   r#   r"   rr   rr      sU        fhhGE***  J J J J Jr#   rr   c                     | }t          | t          t          t          f          rt	          |           } t          | |          S )a  
    A validator that raises a `ValueError` if the initializer is called with a
    value that does not belong in the *options* provided.

    The check is performed using ``value in options``, so *options* has to
    support that operation.

    To keep the validator hashable, dicts, lists, and sets are transparently
    transformed into a `tuple`.

    Args:
        options: Allowed options.

    Raises:
        ValueError:
            With a human readable error message, the attribute (of type
            `attrs.Attribute`), the expected options, and the value it got.

    .. versionadded:: 17.1.0
    .. versionchanged:: 22.1.0
       The ValueError was incomplete until now and only contained the human
       readable error message. Now it contains all the information that has
       been promised since 17.1.0.
    .. versionchanged:: 24.1.0
       *options* that are a list, dict, or a set are now transformed into a
       tuple to keep the validator hashable.
    )r2   ro   dictr`   rp   rr   )rv   repr_optionss     r"   r   r     s=    8 L'D$,-- !.....r#   c                       e Zd Zd Zd ZdS )_IsCallableValidatorc                     t          |          s3d}t          |                    |j        ||j                  |          dS )r-   z?'{name}' must be callable (got {value!r} that is a {actual!r}).)r4   r;   actual)r<   r;   N)callabler   r]   r4   r5   )r8   r9   r:   r;   messages        r"   r=   z_IsCallableValidator.__call__&  se      
	8  #NN% #   	   
	 
	r#   c                     dS )Nz<is_callable validator>r%   rA   s    r"   rB   z_IsCallableValidator.__repr__6  s    ((r#   N)rE   rF   rG   r=   rB   r%   r#   r"   r~   r~   $  s2           ) ) ) ) )r#   r~   c                      t                      S )a  
    A validator that raises a `attrs.exceptions.NotCallableError` if the
    initializer is called with a value for this particular attribute that is
    not callable.

    .. versionadded:: 19.1.0

    Raises:
        attrs.exceptions.NotCallableError:
            With a human readable error message containing the attribute
            (`attrs.Attribute`) name, and the value it got.
    )r~   r%   r#   r"   r   r   :  s      !!!r#   c                   ~    e Zd Z e e                      Z ed e e                                Zd Zd Z	dS )_DeepIterablerj   Ndefaultrk   c                 z    | j         |                      |||           |D ]}|                     |||           dS r-   Niterable_validatormember_validator)r8   r9   r:   r;   members        r"   r=   z_DeepIterable.__call__Q  sY     ".##D$666 	6 	6F!!$f5555	6 	6r#   c                 D    | j         dn	d| j         }d| d| j        dS )N  z<deep_iterable validator forz iterables of r?   r   )r8   iterable_identifiers     r"   rB   z_DeepIterable.__repr__[  sS     &. B0T,00 	8+> 8 8!28 8 8	
r#   )
rE   rF   rG   r
   r   r   r   r   r=   rB   r%   r#   r"   r   r   J  sw        v666 7 7  6 6 6	
 	
 	
 	
 	
r#   r   c                 l    t          | t          t          f          r	t          |  } t	          | |          S )aC  
    A validator that performs deep validation of an iterable.

    Args:
        member_validator: Validator to apply to iterable members.

        iterable_validator:
            Validator to apply to iterable itself (optional).

    Raises
        TypeError: if any sub-validators fail

    .. versionadded:: 19.1.0
    )r2   ro   rp   r	   r   r   r   s     r"   r   r   g  s9     "T5M22 3!12)+=>>>r#   c                       e Zd Z e e                      Z e e                      Z ed e e                                Zd Z	d Z
dS )_DeepMappingrj   Nr   c                     | j         |                      |||           |D ]6}|                     |||           |                     ||||                    7dS r   )mapping_validatorkey_validatorvalue_validator)r8   r9   r:   r;   keys        r"   r=   z_DeepMapping.__call__  su     !-""4u555 	9 	9CtT3///  tU3Z8888	9 	9r#   c                 (    d| j         d| j        dS )Nz,<deep_mapping validator for objects mapping z to r?   )r   r   rA   s    r"   rB   z_DeepMapping.__repr__  s"    qd>PqqX\Xlqqqqr#   )rE   rF   rG   r
   r   r   r   r   r   r=   rB   r%   r#   r"   r   r   {  s        F[[]]333Mf{{}}555Otxx7N7NOOO	9 	9 	9r r r r rr#   r   c                 $    t          | ||          S )a  
    A validator that performs deep validation of a dictionary.

    Args:
        key_validator: Validator to apply to dictionary keys.

        value_validator: Validator to apply to dictionary values.

        mapping_validator:
            Validator to apply to top-level mapping attribute (optional).

    .. versionadded:: 19.1.0

    Raises:
        TypeError: if any sub-validators fail
    )r   )r   r   r   s      r"   r   r     s    " 8IJJJr#   c                   V    e Zd Z e            Z e            Z e            Zd Zd ZdS )_NumberValidatorc                     |                      || j                  s,d|j         d| j         d| j         d| }t	          |          dS )r-   r.   r/   r   : N)compare_funcboundr4   
compare_oprQ   r7   s        r"   r=   z_NumberValidator.__call__  s_       
33 	"RdiRR4?RRTZRR5RRCS//!	" 	"r#   c                 (    d| j          d| j         dS )Nz<Validator for x r   r?   )r   r   rA   s    r"   rB   z_NumberValidator.__repr__  s    B4?BBTZBBBBr#   N)	rE   rF   rG   r
   r   r   r   r=   rB   r%   r#   r"   r   r     sX        FHHEJ688L" " "C C C C Cr#   r   c                 8    t          | dt          j                  S )a  
    A validator that raises `ValueError` if the initializer is called with a
    number larger or equal to *val*.

    The validator uses `operator.lt` to compare the values.

    Args:
        val: Exclusive upper bound for values.

    .. versionadded:: 21.3.0
    <)r   operatorr   vals    r"   r   r          Chk222r#   c                 8    t          | dt          j                  S )a  
    A validator that raises `ValueError` if the initializer is called with a
    number greater than *val*.

    The validator uses `operator.le` to compare the values.

    Args:
        val: Inclusive upper bound for values.

    .. versionadded:: 21.3.0
    z<=)r   r   r   r   s    r"   r   r          Cx{333r#   c                 8    t          | dt          j                  S )a  
    A validator that raises `ValueError` if the initializer is called with a
    number smaller than *val*.

    The validator uses `operator.ge` to compare the values.

    Args:
        val: Inclusive lower bound for values

    .. versionadded:: 21.3.0
    z>=)r   r   r   r   s    r"   r   r     r   r#   c                 8    t          | dt          j                  S )a  
    A validator that raises `ValueError` if the initializer is called with a
    number smaller or equal to *val*.

    The validator uses `operator.ge` to compare the values.

    Args:
       val: Exclusive lower bound for values

    .. versionadded:: 21.3.0
    r?   )r   r   r   r   s    r"   r   r     r   r#   c                   .    e Zd Z e            Zd Zd ZdS )_MaxLengthValidatorc                     t          |          | j        k    r1d|j         d| j         dt          |           }t          |          dS )r-   Length of 'z' must be <= r   N)len
max_lengthr4   rQ   r7   s        r"   r=   z_MaxLengthValidator.__call__  R     u::''W	WWWW3u::WWCS//! ('r#   c                     d| j          dS )Nz<max_len validator for r?   )r   rA   s    r"   rB   z_MaxLengthValidator.__repr__      ;;;;;r#   N)rE   rF   rG   r
   r   r=   rB   r%   r#   r"   r   r     =        J" " "< < < < <r#   r   c                      t          |           S )z
    A validator that raises `ValueError` if the initializer is called
    with a string or iterable that is longer than *length*.

    Args:
        length (int): Maximum length of the string or iterable

    .. versionadded:: 21.3.0
    )r   lengths    r"   r   r          v&&&r#   c                   .    e Zd Z e            Zd Zd ZdS )_MinLengthValidatorc                     t          |          | j        k     r1d|j         d| j         dt          |           }t          |          dS )r-   r   z' must be >= r   N)r   
min_lengthr4   rQ   r7   s        r"   r=   z_MinLengthValidator.__call__  r   r#   c                     d| j          dS )Nz<min_len validator for r?   )r   rA   s    r"   rB   z_MinLengthValidator.__repr__  r   r#   N)rE   rF   rG   r
   r   r=   rB   r%   r#   r"   r   r     r   r#   r   c                      t          |           S )z
    A validator that raises `ValueError` if the initializer is called
    with a string or iterable that is shorter than *length*.

    Args:
        length (int): Minimum length of the string or iterable

    .. versionadded:: 22.1.0
    )r   r   s    r"   r   r     r   r#   c                   .    e Zd Z e            Zd Zd ZdS )_SubclassOfValidatorc                     t          || j                  s-d|j         d| j        d|d}t          ||| j        |          dS )r-   r.   z' must be a subclass of r0   r1   N)
issubclassr3   r4   r6   r7   s        r"   r=   z_SubclassOfValidator.__call__0  sf     %++ 	WdiWWWWEWWWC		  	 	r#   c                     d| j         dS )Nz <subclass_of validator for type r?   r@   rA   s    r"   rB   z_SubclassOfValidator.__repr__=  rC   r#   NrD   r%   r#   r"   r   r   ,  rH   r#   r   c                      t          |           S )a  
    A validator that raises a `TypeError` if the initializer is called with a
    wrong type for this particular attribute (checks are performed using
    `issubclass` therefore it's also valid to pass a tuple of types).

    Args:
        type (type | tuple[type, ...]): The type(s) to check for.

    Raises:
        TypeError:
            With a human readable error message, the attribute (of type
            `attrs.Attribute`), the expected type, and the value it got.
    )r   r@   s    r"   _subclass_ofr   A  rJ   r#   c                       e Zd Z e            Z e ed                    Z e e ee	           e
e                              Zd Zd ZdS )_NotValidatorzCnot_ validator child '{validator!r}' did not raise a captured error)	converterr   rj   c                     	 |                      |||           t          | j                            | j         | j                  || j         || j                  # | j        $ r Y d S w xY w)Nrk   	exc_types)rk   rQ   r<   r]   r   rl   s       r"   r=   z_NotValidator.__call__b  s    	NN4u--- "n"n     	 	 	 ~ 	 	 	DD	s   A 
A('A(c                 (    d| j         d| j        dS )Nz<not_ validator wrapping z, capturing r?   r   rA   s    r"   rB   z_NotValidator.__repr__s  s    \4>\\\\\\r#   N)rE   rF   rG   r
   rk   r   r<   r   r   	Exceptionr   rp   r   r=   rB   r%   r#   r"   r   r   R  s        I
&!/-
 
  C -)\)44*{511
 
 
  I  "] ] ] ] ]r#   r   )r<   r   c                l    	 t          |          }n# t          $ r |f}Y nw xY wt          | ||          S )a:  
    A validator that wraps and logically 'inverts' the validator passed to it.
    It will raise a `ValueError` if the provided validator *doesn't* raise a
    `ValueError` or `TypeError` (by default), and will suppress the exception
    if the provided validator *does*.

    Intended to be used with existing validators to compose logic without
    needing to create inverted variants, for example, ``not_(in_(...))``.

    Args:
        validator: A validator to be logically inverted.

        msg (str):
            Message to raise if validator fails. Formatted with keys
            ``exc_types`` and ``validator``.

        exc_types (tuple[type, ...]):
            Exception type(s) to capture. Other types raised by child
            validators will not be intercepted and pass through.

    Raises:
        ValueError:
            With a human readable error message, the attribute (of type
            `attrs.Attribute`), the validator that failed to raise an
            exception, the value it got, and the expected exception types.

    .. versionadded:: 22.2.0
    )rp   r6   r   )rk   r<   r   s      r"   r   r   w  sN    :!)$$		 ! ! !L			!C333s    ""c                   .    e Zd Z e            Zd Zd ZdS )_OrValidatorc                     | j         D ]"}	  ||||            d S # t          $ r Y w xY wd| j         d|}t          |          )NzNone of z satisfied for value )
validatorsr   rQ   )r8   r9   r:   r;   vr<   s         r"   r=   z_OrValidator.__call__  s}     	 	A$e$$$     
 KJJJJoos   
((c                     d| j         dS )Nz<or validator wrapping r?   )r   rA   s    r"   rB   z_OrValidator.__repr__  s    =====r#   N)rE   rF   rG   r
   r   r=   rB   r%   r#   r"   r   r     s=        J
 
 
> > > > >r#   r   c                      g }| D ]4}|                     t          |t                    r|j        n|g           5t          t	          |                    S )a  
    A validator that composes multiple validators into one.

    When called on a value, it runs all wrapped validators until one of them is
    satisfied.

    Args:
        validators (~collections.abc.Iterable[typing.Callable]):
            Arbitrary number of validators.

    Raises:
        ValueError:
            If no validator is satisfied. Raised with a human-readable error
            message listing all the wrapped validators and the value that
            failed all of them.

    .. versionadded:: 24.1.0
    )extendr2   r   r   rp   )r   valsr   s      r"   r   r     sZ    & D J JJq,$?$?HALLaSIIIId$$$r#   )r   Nri   )5__doc__r   rY   
contextlibr   r   _configr   r   _maker   r	   r
   r   
convertersr   
exceptionsr   __all__r   r   r   r+   r   rM   r   rg   r   rr   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rQ   r6   r   r   r   r%   r#   r"   <module>r      s     				 % % % % % %       ; ; ; ; ; ; ; ; 5 5 5 5 5 5 5 5 5 5 5 5 ' ' ' ' ' ' ( ( ( ( ( (  .% % %$	$ 	$ 	$ ! ! !" E4000A A A A A A A 10A(& & &" E$d+++F F F F F F F ,+F*-4 -4 -4 -4` E4000
F 
F 
F 
F 
F 
F 
F 10
F) ) )* E4000J J J J J J J 10J. /  /  /F ED111) ) ) ) ) ) ) 21)*" " "  E4000
 
 
 
 
 
 
 10
8? ? ? ?( E4000r r r r r r r 10r(K K K K( E$d+++C C C C C C C ,+C"3 3 34 4 44 4 43 3 3 E$d+++< < < < < < < ,+<
' 
' 
' E$d+++< < < < < < < ,+<
' 
' 
' E4000A A A A A A A 10A(& & &" E4000!] !] !] !] !] !] !] 10!]H  J	+B !4 !4 !4 !4 !4H E4000> > > > > > > 10>&% % % % %r#   