
    dP                     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# 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 d0 d1                      Z+d2 Z, eddd           G d3 d4                      Z-d5 Z. eddd           G d6 d7                      Z/d8 Z0 eddd           G d9 d:                      Z1de2e3fd;d<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providesset_disabledc                 &    t          |             dS )a  
    Globally disable or enable running validators.

    By default, they are run.

    :param disabled: If ``True``, disable running all validators.
    :type disabled: bool

    .. warning::

        This function is not thread-safe!

    .. versionadded:: 21.3.0
    Nr   )r   s    S/home/feoh/.local/pipx/venvs/poetry/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.

    :return: ``True`` if validators are currently disabled.
    :rtype: bool

    .. 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   I   sM       u!4     4    s   ( 9FT)reprslotshashc                   .    e Zd Z e            Zd Zd ZdS )_InstanceOfValidatorc                     t          || j                  s=t          d                    |j        | j        |j        |          || j        |          dS )P
        We use a callable class to be able to change the ``__repr__``.
        z?'{name}' must be {type!r} (got {value!r} that is a {actual!r}).)nametypeactualvalueN)
isinstancer/   	TypeErrorformatr.   	__class__selfinstattrr1   s       r"   __call__z_InstanceOfValidator.__call___   sl     %++ 	%v ?	  &     	  	 	r#   c                 8    d                     | j                  S )Nz)<instance_of validator for type {type!r}>r/   r4   r/   r7   s    r"   __repr__z_InstanceOfValidator.__repr__q   %    :AA B 
 
 	
r#   N__name__
__module____qualname__r
   r/   r:   r?   r%   r#   r"   r+   r+   [   s=        688D  $
 
 
 
 
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).

    :param type: The type to check for.
    :type type: type or tuple of type

    :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   w         %%%r#   )r'   frozenr(   c                   B    e Zd Z e            Z e            Zd Zd ZdS )_MatchesReValidatorc                     |                      |          s<t          d                    |j        | j        j        |          || j        |          dS )r-   z9'{name}' must match regex {pattern!r} ({value!r} doesn't))r.   patternr1   N)
match_func
ValueErrorr4   r.   rK   r6   s       r"   r:   z_MatchesReValidator.__call__   sh     u%% 		''-vDL,@ (. ( (   		 		r#   c                 8    d                     | j                  S )Nz.<matches_re validator for pattern {pattern!r}>)rK   )r4   rK   r>   s    r"   r?   z_MatchesReValidator.__repr__   s%    ?FFL G 
 
 	
r#   N)rB   rC   rD   r
   rK   rL   r:   r?   r%   r#   r"   rI   rI      sH        fhhGJ  
 
 
 
 
r#   rI   c                    t           j        dt           j        t           j        f}||vrYt	          d                    d                    t          d t          |          D                                                     t          | t                    r|rt          d          | }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*.

    :param regex: a regex string or precompiled pattern to match against
    :param int flags: flags that will be passed to the underlying re function
        (default 0)
    :param callable func: 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)rB   ).0es     r"   	<genexpr>zmatches_re.<locals>.<genexpr>   s?        78(aj2F     r#   zR'flags' can only be used with a string pattern; pass flags to re.compile() instead)re	fullmatchsearchmatchrM   r4   joinsortedsetr2   r   r3   compilerI   )regexflagsfuncvalid_funcsrK   rL   s         r"   r   r      s     <ry"(;K;'..		  <?<L<L      
 
 	
 %!! + 	5   *UE**rx]

			^

&
w
333r#   c                   .    e Zd Z e            Zd Zd ZdS )_ProvidesValidatorc                     | j                             |          s7t          d                    |j        | j         |          || j         |          dS )r-   z<'{name}' must provide {interface!r} which {value!r} doesn't.)r.   	interfacer1   N)rd   
providedByr3   r4   r.   r6   s       r"   r:   z_ProvidesValidator.__call__   si     ~((// 		!6dnE "     		 		r#   c                 8    d                     | j                  S )Nz0<provides validator for interface {interface!r}>)rd   )r4   rd   r>   s    r"   r?   z_ProvidesValidator.__repr__   s%    AHHn I 
 
 	
r#   N)rB   rC   rD   r
   rd   r:   r?   r%   r#   r"   rb   rb      s=        I  
 
 
 
 
r#   rb   c                 b    ddl }|                    dt          d           t          |           S )aE  
    A validator that raises a `TypeError` if the initializer is called
    with an object that does not provide the requested *interface* (checks are
    performed using ``interface.providedBy(value)`` (see `zope.interface
    <https://zopeinterface.readthedocs.io/en/latest/>`_).

    :param interface: The interface to check for.
    :type interface: ``zope.interface.Interface``

    :raises TypeError: With a human readable error message, the attribute
        (of type `attrs.Attribute`), the expected interface, and the
        value it got.

    .. deprecated:: 23.1.0
    r   NzZattrs's zope-interface support is deprecated and will be removed in, or after, April 2024.   )
stacklevel)warningswarnDeprecationWarningrb   )rd   rj   s     r"   r   r      sC      OOOMM	 	     i(((r#   c                   .    e Zd Z e            Zd Zd ZdS )_OptionalValidatorc                 <    |d S |                      |||           d S N	validatorr6   s       r"   r:   z_OptionalValidator.__call__	  s(    =FtT5)))))r#   c                 R    d                     t          | j                            S )Nz'<optional validator for {what} or None>)what)r4   r'   rr   r>   s    r"   r?   z_OptionalValidator.__repr__  s-    8??dn%% @ 
 
 	
r#   N)rB   rC   rD   r
   rr   r:   r?   r%   r#   r"   rn   rn     s=        I* * *
 
 
 
 
r#   rn   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.

    :param Callable | tuple[Callable] | list[Callable] validator: 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tuplern   r   rq   s    r"   r   r     s>     )dE]++ <!-	":":;;;i(((r#   c                   .    e Zd Z e            Zd Zd ZdS )_InValidatorc                     	 || j         v }n# t          $ r d}Y nw xY w|s7t          d                    |j        | j         |          || j         |          d S )NFz/'{name}' must be in {options!r} (got {value!r}))r.   optionsr1   )r{   r3   rM   r4   r.   )r7   r8   r9   r1   
in_optionss        r"   r:   z_InValidator.__call__,  s    	$,.JJ 	 	 	JJJ	  	AHHDL I     	 	s   	 c                 8    d                     | j                  S )Nz(<in_ validator with options {options!r}>r{   )r4   r{   r>   s    r"   r?   z_InValidator.__repr__<  s%    9@@L A 
 
 	
r#   N)rB   rC   rD   r
   r{   r:   r?   r%   r#   r"   ry   ry   (  s=        fhhG   
 
 
 
 
r#   ry   c                      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``.

    :param options: Allowed options.
    :type options: list, tuple, `enum.Enum`, ...

    :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.
    )ry   r~   s    r"   r   r   B  s    &    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}).)r.   r1   r0   )msgr1   N)callabler   r4   r.   r5   )r7   r8   r9   r1   messages        r"   r:   z_IsCallableValidator.__call__Z  se      
	8  #NN% #   	   
	 
	r#   c                     dS )Nz<is_callable validator>r%   r>   s    r"   r?   z_IsCallableValidator.__repr__j  s    ((r#   N)rB   rC   rD   r:   r?   r%   r#   r"   r   r   X  s2           ) ) ) ) )r#   r   c                      t                      S )ax  
    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   n  s      !!!r#   c                   ~    e Zd Z e e                      Z ed e e                                Zd Zd Z	dS )_DeepIterablerq   Ndefaultrr   c                 z    | j         |                      |||           |D ]}|                     |||           dS r-   N)iterable_validatormember_validator)r7   r8   r9   r1   members        r"   r:   z_DeepIterable.__call__  sY     ".##D$666 	6 	6F!!$f5555	6 	6r#   c                 `    | j         dn	d| j         }d                    || j                  S )N  zJ<deep_iterable validator for{iterable_identifier} iterables of {member!r}>)iterable_identifierr   )r   r4   r   )r7   r   s     r"   r?   z_DeepIterable.__repr__  sN     &. B0T,00 	(
& 3(  
 
	
r#   )
rB   rC   rD   r
   r   r   r   r   r:   r?   r%   r#   r"   r   r   }  sw        v666 7 7  6 6 6
 
 
 
 
r#   r   c                 l    t          | t          t          f          r	t          |  } t	          | |          S )a4  
    A validator that performs deep validation of an iterable.

    :param member_validator: Validator(s) to apply to iterable members
    :param iterable_validator: Validator to apply to iterable itself
        (optional)

    .. versionadded:: 19.1.0

    :raises TypeError: if any sub-validators fail
    )r2   rv   rw   r	   r   r   r   s     r"   r   r     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 )_DeepMappingrq   Nr   c                     | j         |                      |||           |D ]6}|                     |||           |                     ||||                    7dS r   )mapping_validatorkey_validatorvalue_validator)r7   r8   r9   r1   keys        r"   r:   z_DeepMapping.__call__  su     !-""4u555 	9 	9CtT3///  tU3Z8888	9 	9r#   c                 D    d                     | j        | j                  S )NzA<deep_mapping validator for objects mapping {key!r} to {value!r}>)r   r1   )r4   r   r   r>   s    r"   r?   z_DeepMapping.__repr__  s"    O
&T't/C&
D
D	Er#   )rB   rC   rD   r
   r   r   r   r   r   r:   r?   r%   r#   r"   r   r     s        F[[]]333Mf{{}}555Otxx7N7NOOO	9 	9 	9E E E E Er#   r   c                 $    t          | ||          S )a}  
    A validator that performs deep validation of a dictionary.

    :param key_validator: Validator to apply to dictionary keys
    :param value_validator: Validator to apply to dictionary values
    :param 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                  s5t          d                    |j        | j        | j        |                    dS )r-   z&'{name}' must be {op} {bound}: {value})r.   opboundr1   N)compare_funcr   rM   r4   r.   
compare_opr6   s       r"   r:   z_NumberValidator.__call__  se       
33 	8??*	 @    	 	r#   c                 D    d                     | j        | j                  S )Nz<Validator for x {op} {bound}>)r   r   )r4   r   r   r>   s    r"   r?   z_NumberValidator.__repr__  s(    /66dj 7 
 
 	
r#   N)	rB   rC   rD   r
   r   r   r   r:   r?   r%   r#   r"   r   r     sS        FHHEJ688L  
 
 
 
 
r#   r   c                 8    t          | dt          j                  S )z
    A validator that raises `ValueError` if the initializer is called
    with a number larger or equal to *val*.

    :param 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 )z
    A validator that raises `ValueError` if the initializer is called
    with a number greater than *val*.

    :param 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 )z
    A validator that raises `ValueError` if the initializer is called
    with a number smaller than *val*.

    :param 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 )z
    A validator that raises `ValueError` if the initializer is called
    with a number smaller or equal to *val*.

    :param val: Exclusive lower bound for values

    .. versionadded:: 21.3.0
    >)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    r<t          d                    |j        | j        t          |                              dS )r-   z*Length of '{name}' must be <= {max}: {len})r.   maxlenN)r   
max_lengthrM   r4   r.   r6   s       r"   r:   z_MaxLengthValidator.__call__#  [     u::''<CCSZZ D     ('r#   c                     d| j          dS )Nz<max_len validator for r   )r   r>   s    r"   r?   z_MaxLengthValidator.__repr__.      ;;;;;r#   N)rB   rC   rD   r
   r   r:   r?   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*.

    :param int length: Maximum length of the string or iterable

    .. versionadded:: 21.3.0
    )r   lengths    r"   r   r   2       v&&&r#   c                   .    e Zd Z e            Zd Zd ZdS )_MinLengthValidatorc           	          t          |          | j        k     r<t          d                    |j        | j        t          |                              dS )r-   z*Length of '{name}' must be => {min}: {len})r.   minr   N)r   
min_lengthrM   r4   r.   r6   s       r"   r:   z_MinLengthValidator.__call__B  r   r#   c                     d| j          dS )Nz<min_len validator for r   )r   r>   s    r"   r?   z_MinLengthValidator.__repr__M  r   r#   N)rB   rC   rD   r
   r   r:   r?   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*.

    :param int length: Minimum length of the string or iterable

    .. versionadded:: 22.1.0
    )r   r   s    r"   r   r   Q  r   r#   c                   .    e Zd Z e            Zd Zd ZdS )_SubclassOfValidatorc                     t          || j                  s7t          d                    |j        | j        |          || j        |          dS )r-   z8'{name}' must be a subclass of {type!r} (got {value!r}).)r.   r/   r1   N)
issubclassr/   r3   r4   r.   r6   s       r"   r:   z_SubclassOfValidator.__call__a  sg     %++ 	##)6 $* $ $
 	
 
 
	 	r#   c                 8    d                     | j                  S )Nz)<subclass_of validator for type {type!r}>r<   r=   r>   s    r"   r?   z_SubclassOfValidator.__repr__r  r@   r#   NrA   r%   r#   r"   r   r   ]  s=        688D  "
 
 
 
 
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).

    :param type: The type to check for.
    :type type: type or tuple of types

    :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   x  rF   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   rq   c                     	 |                      |||           t          | j                            | j         | j                  || j         || j                  # | j        $ r Y d S w xY w)N)rr   	exc_types)rr   rM   r   r4   r   r6   s       r"   r:   z_NotValidator.__call__  s    	NN4u--- "n"n     	 	 	 ~ 	 	 	DD	s   A 
A('A(c                 D    d                     | j        | j                  S )Nz;<not_ validator wrapping {what!r}, capturing {exc_types!r}>)rt   r   )r4   rr   r   r>   s    r"   r?   z_NotValidator.__repr__  s(    L
&n  
 
	
r#   N)rB   rC   rD   r
   rr   r   r   r   r   	Exceptionr   rw   r   r:   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_(...))``.

    :param validator: A validator to be logically inverted.
    :param msg: Message to raise if validator fails.
        Formatted with keys ``exc_types`` and ``validator``.
    :type msg: str
    :param exc_types: 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
    )rw   r3   r   )rr   r   r   s      r"   r   r     sN    4!)$$		 ! ! !L			!C333s    "")r   Nrp   )5__doc__r   rU   
contextlibr   r   _configr   r   _maker   r	   r
   r   
convertersr   
exceptionsr   __all__r   r   r   r+   r   rI   r   rb   r   rn   r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rM   r3   r   r%   r#   r"   <module>r      s   
  				 % % % % % %       ; ; ; ; ; ; ; ; 5 5 5 5 5 5 5 5 5 5 5 5 ' ' ' ' ' ' ( ( ( ( ( (  .% % %$	$ 	$ 	$ ! ! !" ED)))
 
 
 
 
 
 
 *)
6& & &  E$d+++
 
 
 
 
 
 
 ,+
2-4 -4 -4 -4` ED)))
 
 
 
 
 
 
 *)
0) ) )6 ED)))
 
 
 
 
 
 
 *)
) ) )& ED)))
 
 
 
 
 
 
 *)
2! ! !, ET***) ) ) ) ) ) ) +*)*" " " ED)))
 
 
 
 
 
 
 *)
>? ? ? ?" ED)))E E E E E E E *)E,K K K K  E$d+++
 
 
 
 
 
 
 ,+
2	3 	3 	3	4 	4 	4	4 	4 	4	3 	3 	3 E$d+++< < < < < < < ,+<$	' 	' 	' E$d+++< < < < < < < ,+<$	' 	' 	' ED)))
 
 
 
 
 
 
 *)
4& & &  ED)))&
 &
 &
 &
 &
 &
 &
 *)&
R  J	+B 4 4 4 4 4 4 4r#   