
     i1T                     j   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    W/root/.openclaw/workspace/.venvs/songid/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               #      K   t                      } t          d           	 dV  t          |            dS # t          |            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
    .. versionchanged:: 26.1.0 The contextmanager is nestable.
    FNr   )prevs    r"   r   r   H   sX       Du!4     4    s	   6 A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 >r4   r9   s    r"   __repr__z_InstanceOfValidator.__repr__m       @$)@@@@r#   N__name__
__module____qualname__r   r4   r>   rC   r%   r#   r"   r,   r,   \   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,   rA   s    r"   r   r   q         %%%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_funcr5   pattern
ValueErrorr8   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@   )rQ   rB   s    r"   rC   z_MatchesReValidator.__repr__   s    EDLEEEEr#   N)rF   rG   rH   r   rQ   rP   r>   rC   r%   r#   r"   rN   rN      sM        fhhGJ  F F F F Fr#   rN   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)rF   ).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setrR   r3   r   r7   compilerN   )regexflagsfuncvalid_funcsr=   rQ   rP   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r9   r:   r;   r<   s       r"   r>   z_OptionalValidator.__call__   s(    =FtT5)))))r#   c                     d| j         dS )Nz<optional validator for z	 or None>rk   rB   s    r"   rC   z_OptionalValidator.__repr__   s    E$.EEEEr#   N)rF   rG   rH   r   rl   r>   rC   r%   r#   r"   rh   rh      sB        I* * *F F F F Fr#   rh   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.
    )r3   listtuplerh   r	   rk   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 r1   ))optionsr7   r5   _original_optionsrR   )r9   r:   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@   )rx   rB   s    r"   rC   z_InValidator.__repr__   s    Id.DIIIIr#   N)rF   rG   rH   r   rw   rx   r>   rC   r%   r#   r"   rs   rs      sU        fhhGE***  J J J J Jr#   rs   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.
    )r3   rp   dictra   rq   rs   )rw   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}).)r5   r<   actual)r=   r<   N)callabler   r^   r5   r6   )r9   r:   r;   r<   messages        r"   r>   z_IsCallableValidator.__call__(  se      
	8  #NN% #   	   
	 
	r#   c                     dS )Nz<is_callable validator>r%   rB   s    r"   rC   z_IsCallableValidator.__repr__8  s    ((r#   N)rF   rG   rH   r>   rC   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 )_DeepIterablerk   N)defaultrl   c                 z    | j         |                      |||           |D ]}|                     |||           dS r.   Niterable_validatormember_validator)r9   r:   r;   r<   members        r"   r>   z_DeepIterable.__call__S  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   )r9   iterable_identifiers     r"   rC   z_DeepIterable.__repr__]  sS     &. B0T,00 	8+> 8 8!28 8 8	
r#   )
rF   rG   rH   r   r   r   r   r   r>   rC   r%   r#   r"   r   r   L  sw        v666 7 7  6 6 6	
 	
 	
 	
 	
r#   r   c                     t          | t          t          f          r	t          |  } t          |t          t          f          r	t          | }t	          | |          S )a  
    A validator that performs deep validation of an iterable.

    Args:
        member_validator: Validator(s) to apply to iterable members.

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

    Raises
        TypeError: if any sub-validators fail

    .. versionadded:: 19.1.0

    .. versionchanged:: 25.4.0
       *member_validator* and *iterable_validator* can now be a list or tuple
       of validators.
    )r3   rp   rq   r
   r   r   r   s     r"   r   r   i  s\    & "T5M22 3!12$tUm44 7!#56)+=>>>r#   c                       e Zd Z e e e                                Z e e e                                Z e e e                                Zd Z	d Z
dS )_DeepMappingrk   c                     | j         |                      |||           |D ]D}| j        |                     |||           | j        |                     ||||                    EdS r   )mapping_validatorkey_validatorvalue_validator)r9   r:   r;   r<   keys        r"   r>   z_DeepMapping.__call__  s     !-""4u555 	= 	=C!-""4s333#/$$T4s<<<		= 	=r#   c                 (    d| j         d| j        dS )Nz,<deep_mapping validator for objects mapping z to r@   )r   r   rB   s    r"   rC   z_DeepMapping.__repr__  s"    qd>PqqX\Xlqqqqr#   N)rF   rG   rH   r   r   r   r   r   r   r>   rC   r%   r#   r"   r   r     s        FXXkkmm%<%<===Mfxx'>'>???O++--)@)@AAA= = =r r r r rr#   r   c                 ,   | |d}t          |          t          | t          t          f          r	t	          |  } t          |t          t          f          r	t	          | }t          |t          t          f          r	t	          | }t          | ||          S )a  
    A validator that performs deep validation of a dictionary.

    All validators are optional, but at least one of *key_validator* or
    *value_validator* must be provided.

    Args:
        key_validator: Validator(s) to apply to dictionary keys.

        value_validator: Validator(s) to apply to dictionary values.

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

    .. versionadded:: 19.1.0

    .. versionchanged:: 25.4.0
       *key_validator* and *value_validator* are now optional, but at least one
       of them must be provided.

    .. versionchanged:: 25.4.0
       *key_validator*, *value_validator*, and *mapping_validator* can now be a
       list or tuple of validators.

    Raises:
        TypeError: If any sub-validator fails on validation.

        ValueError:
            If neither *key_validator* nor *value_validator* is provided on
            instantiation.
    NzAAt least one of key_validator or value_validator must be provided)rR   r3   rp   rq   r
   r   )r   r   r   r=   s       r"   r   r     s    D !8O 	 oo-$// -m,/D%=11 10#dE]33 5 "34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/   r0   r   : N)compare_funcboundr5   
compare_oprR   r8   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   rB   s    r"   rC   z_NumberValidator.__repr__  s    B4?BBTZBBBBr#   N)	rF   rG   rH   r   r   r   r   r>   rC   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.gt` 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_lengthr5   rR   r8   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   rB   s    r"   rC   z_MaxLengthValidator.__repr__&      ;;;;;r#   N)rF   rG   rH   r   r   r>   rC   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_lengthr5   rR   r8   s        r"   r>   z_MinLengthValidator.__call__;  r   r#   c                     d| j          dS )Nz<min_len validator for r@   )r   rB   s    r"   rC   z_MinLengthValidator.__repr__C  r   r#   N)rF   rG   rH   r   r   r>   rC   r%   r#   r"   r   r   7  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   G  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 r1   r2   N)
issubclassr4   r5   r7   r8   s        r"   r>   z_SubclassOfValidator.__call__X  sf     %++ 	WdiWWWWEWWWC		  	 	r#   c                     d| j         dS )Nz <subclass_of validator for type r@   rA   rB   s    r"   rC   z_SubclassOfValidator.__repr__e  rD   r#   NrE   r%   r#   r"   r   r   T  rI   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   rA   s    r"   _subclass_ofr   i  rK   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   rk   c                     	 |                      |||           t          | j                            | j         | j                  || j         || j                  # | j        $ r Y d S w xY w)Nrl   	exc_types)rl   rR   r=   r^   r   rm   s       r"   r>   z_NotValidator.__call__  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   rB   s    r"   rC   z_NotValidator.__repr__  s    \4>\\\\\\r#   N)rF   rG   rH   r   rl   r   r=   r   r   	Exceptionr   rq   r   r>   rC   r%   r#   r"   r   r   z  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
    )rq   r7   r   )rl   r=   r   s      r"   r   r     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   rR   )r9   r:   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   rB   s    r"   rC   z_OrValidator.__repr__  s    =====r#   N)rF   rG   rH   r   r   r>   rC   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
    )extendr3   r   r   rq   )r   valsr   s      r"   r   r     sZ    & D J JJq,$?$?HALLaSIIIId$$$r#   )r   Nrj   )NNN)5__doc__r   rZ   
contextlibr   r   _configr   r   _maker	   r
   r   r   
convertersr   
exceptionsr   __all__r    r   r   r,   r   rN   r   rh   r   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rR   r7   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? ? ? ?4 E4000r r r r r r r 10r. AE/K /K /K /Kd 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#   