
    6hA                        S r SSKrSSKrSSKJr  SSKJrJr  SSKJ	r	J
r
JrJr  SSKJr   \R                  r/ S	QrS
 rS r\S 5       r\" SSSS9 " S S5      5       rS r\" SSSS9 " S S5      5       rS5S jr\" SSSS9 " S S5      5       rS r\" SSSS9 " S S5      5       rS r\" SSSS9 " S S5      5       rS r \" SSSS9 " S  S!5      5       r!S" r"\" SSSS9 " S# S$5      5       r#S6S% jr$\" SSSS9 " S& S'5      5       r%S6S( jr&\" SSSS9 " S) S*5      5       r'S+ r(S, r)S- r*S. r+\" SSSS9 " S/ S05      5       r,S1 r-\" SSSS9 " S2 S35      5       r.S4 r/g! \ a    \" \R$                  " S5      5      r GNKf = f)7z
Commonly useful validators.
    N)contextmanager   )get_run_validatorsset_run_validators)_AndValidatorand_attribattrs)NotCallableError )r   deep_iterabledeep_mappingdisabledgeget_disabledgtin_instance_ofis_callablelelt
matches_remax_lenmin_lenoptionalprovidesset_disabledc                 $    [        U (       + 5        g)z
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    F/usr/lib/python3/dist-packages/mercurial/thirdparty/attr/validators.pyr   r   .   s     8|$    c                       [        5       (       + $ )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               #   b   #    [        S5         Sv   [        S5        g! [        S5        f = f7f)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   L   s(      u!4 4 s   / /,/FT)reprslotshashc                   .    \ rS rSr\" 5       rS rS rSrg)_InstanceOfValidator^   c           	          [        X0R                  5      (       dF  [        SR                  UR                  U R                  UR
                  US9UU R                  U5      eg)@
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attrr0   s       r    __call___InstanceOfValidator.__call__b   s`     %++%v ??	  &   		  ,r!   c                 4    SR                  U R                  S9$ )Nz)<instance_of validator for type {type!r}>r.   )r3   r.   r6   s    r    __repr___InstanceOfValidator.__repr__t   s"    :AA B 
 	
r!   r#   N)	__name__
__module____qualname____firstlineno__r	   r.   r9   r>   __static_attributes__r#   r!   r    r)   r)   ^   s    8D$
r!   r)   c                     [        U 5      $ )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 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    r   r   z   s      %%r!   )r%   frozenr&   c                   <    \ rS rSr\" 5       r\" 5       rS rS rSr	g)_MatchesReValidator   c                     U R                  U5      (       dE  [        SR                  UR                  U R                  R                  US9UU R                  U5      eg)r,   z9'{name}' must match regex {pattern!r} ({value!r} doesn't))r-   patternr0   N)
match_func
ValueErrorr3   r-   rK   r5   s       r    r9   _MatchesReValidator.__call__   s]     u%%''-vDLL,@,@ (. (   &r!   c                 4    SR                  U R                  S9$ )Nz.<matches_re validator for pattern {pattern!r}>)rK   )r3   rK   r=   s    r    r>   _MatchesReValidator.__repr__   s"    ?FFLL G 
 	
r!   r#   N)
r@   rA   rB   rC   r	   rK   rL   r9   r>   rD   r#   r!   r    rH   rH      s    hGJ
r!   rH   c                    [         R                  S[         R                  [         R                  4nX#;  aB  [	        SR                  SR                  [        S [        U5       5       5      5      5      5      e[        U [        5      (       a  U(       a  [        S5      eU nO[         R                  " X5      nU[         R                  L a  UR                  nO,U[         R                  L a  UR                  nOUR                  n[        XE5      $ )al  
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   \   #    U  H"  o=(       a    UR                   =(       d    S v   M$     g7f)NoneN)r@   ).0es     r    	<genexpr>matches_re.<locals>.<genexpr>   s#      <Lq(ajj2F2<Ls   *,zR'flags' can only be used with a string pattern; pass flags to re.compile() instead)re	fullmatchsearchmatchrM   r3   joinsortedsetr1   Patternr2   compilerH   )regexflagsfuncvalid_funcsrK   rL   s         r    r   r      s      <<ryy"((;K'..		 <?<L 
 	
 %!!5  **U*rxx]]
		^^
&&
w33r!   c                   .    \ rS rSr\" 5       rS rS rSrg)_ProvidesValidator   c                     U R                   R                  U5      (       d;  [        SR                  UR                  U R                   US9UU R                   U5      eg)r,   z<'{name}' must provide {interface!r} which {value!r} doesn't.)r-   	interfacer0   N)ri   
providedByr2   r3   r-   r5   s       r    r9   _ProvidesValidator.__call__   s]     ~~((//!6dnnE "    0r!   c                 4    SR                  U R                  S9$ )Nz0<provides validator for interface {interface!r}>ri   )r3   ri   r=   s    r    r>   _ProvidesValidator.__repr__   s"    AHHnn I 
 	
r!   r#   N)	r@   rA   rB   rC   r	   ri   r9   r>   rD   r#   r!   r    rf   rf      s    I
r!   rf   c                     [        U 5      $ )a  
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.
)rf   rm   s    r    r   r      s     i((r!   c                   .    \ rS rSr\" 5       rS rS rSrg)_OptionalValidator   c                 0    Uc  g U R                  XU5        g N	validatorr5   s       r    r9   _OptionalValidator.__call__  s    =t5)r!   c                 F    SR                  [        U R                  5      S9$ )Nz'<optional validator for {what} or None>)what)r3   r%   rv   r=   s    r    r>   _OptionalValidator.__repr__  s'    8??dnn% @ 
 	
r!   r#   N)	r@   rA   rB   rC   r	   rv   r9   r>   rD   r#   r!   r    rq   rq      s    I*
r!   rq   c                 j    [        U [        5      (       a  [        [        U 5      5      $ [        U 5      $ )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 validator: A validator (or a list of validators) that is used for
    non-``None`` values.
:type validator: callable or `list` of callables.

.. versionadded:: 15.1.0
.. versionchanged:: 17.1.0 *validator* can be a list of validators.
)r1   listrq   r   ru   s    r    r   r     s,     )T""!-	":;;i((r!   c                   .    \ rS rSr\" 5       rS rS rSrg)_InValidatori   c                      X0R                   ;   nU(       d;  [        SR                  UR                  U R                   US9UU R                   U5      eg ! [         a    Sn NQf = f)NFz/'{name}' must be in {options!r} (got {value!r}))r-   optionsr0   )r   r2   rM   r3   r-   )r6   r7   r8   r0   
in_optionss        r    r9   _InValidator.__call__$  sr    	,,.J AHHDLL I      	J	s   A A"!A"c                 4    SR                  U R                  S9$ )Nz(<in_ validator with options {options!r}>r   )r3   r   r=   s    r    r>   _InValidator.__repr__4  s"    9@@LL A 
 	
r!   r#   N)	r@   rA   rB   rC   r	   r   r9   r>   rD   r#   r!   r    r~   r~      s    hG 
r!   r~   c                     [        U 5      $ )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.
)r~   r   s    r    r   r   :  s    &   r!   c                        \ rS rSrS rS rSrg)_IsCallableValidatoriP  c                     [        U5      (       d.  Sn[        UR                  UR                  X3R                  S9US9eg)r,   z?'{name}' must be callable (got {value!r} that is a {actual!r}).)r-   r0   r/   )msgr0   N)callabler   r3   r-   r4   )r6   r7   r8   r0   messages        r    r9   _IsCallableValidator.__call__R  sN     8  #NN% #  	  r!   c                     g)Nz<is_callable validator>r#   r=   s    r    r>   _IsCallableValidator.__repr__b  s    (r!   r#   N)r@   rA   rB   rC   r9   r>   rD   r#   r!   r    r   r   P  s     )r!   r   c                      [        5       $ )aX  
A validator that raises a `attr.exceptions.NotCallableError` if the
initializer is called with a value for this particular attribute
that is not callable.

.. versionadded:: 19.1.0

:raises `attr.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   f  s      !!r!   c                   Z    \ rS rSr\" \" 5       S9r\" S\" \" 5       5      S9rS r	S r
Srg)_DeepIterableiu  ru   Ndefaultrv   c                 x    U R                   b  U R                  XU5        U H  nU R                  XU5        M     gr,   N)iterable_validatormember_validator)r6   r7   r8   r0   members        r    r9   _DeepIterable.__call__|  s:     "".##D6F!!$f5 r!   c                     U R                   c  SOSR                  U R                   S9nSR                  UU R                  S9$ )Nr   z {iterable!r})iterablezJ<deep_iterable validator for{iterable_identifier} iterables of {member!r}>)iterable_identifierr   )r   r3   r   )r6   r   s     r    r>   _DeepIterable.__repr__  sV     &&.  ''1H1H'I 	(
& 3((  
	
r!   r#   )r@   rA   rB   rC   r	   r   r   r   r   r9   r>   rD   r#   r!   r    r   r   u  s0    6 76
r!   r   c                 ^    [        U [        [        45      (       a  [        U 6 n [	        X5      $ )a  
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
)r1   r|   tupler   r   )r   r   s     r    r   r     s.     "T5M22!12)>>r!   c                   p    \ rS rSr\" \" 5       S9r\" \" 5       S9r\" S\" \" 5       5      S9r	S r
S rSrg)_DeepMappingi  ru   Nr   c                     U R                   b  U R                  XU5        U H)  nU R                  XU5        U R                  XX4   5        M+     gr   )mapping_validatorkey_validatorvalue_validator)r6   r7   r8   r0   keys        r    r9   _DeepMapping.__call__  sL     !!-""4u5Ct3/  UZ8 r!   c                 J    SR                  U R                  U R                  S9$ )NzA<deep_mapping validator for objects mapping {key!r} to {value!r}>)r   r0   )r3   r   r   r=   s    r    r>   _DeepMapping.__repr__  s%    O
&T''t/C/C&
D	Er!   r#   )r@   rA   rB   rC   r	   r   r   r   r   r   r9   r>   rD   r#   r!   r    r   r     s9    []3M{}5Otx7NO	9Er!   r   c                     [        XU5      $ )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Jr!   c                   J    \ rS rSr\" 5       r\" 5       r\" 5       rS rS r	Sr
g)_NumberValidatori  c           	          U R                  X0R                  5      (       d9  [        SR                  UR                  U R
                  U R                  US95      eg)r,   z&'{name}' must be {op} {bound}: {value})r-   opboundr0   N)compare_funcr   rM   r3   r-   
compare_opr5   s       r    r9   _NumberValidator.__call__  sW       

338??**	 @   4r!   c                 J    SR                  U R                  U R                  S9$ )Nz<Validator for x {op} {bound}>)r   r   )r3   r   r   r=   s    r    r>   _NumberValidator.__repr__  s'    /66djj 7 
 	
r!   r#   N)r@   rA   rB   rC   r	   r   r   r   r9   r>   rD   r#   r!   r    r   r     s!    HEJ8L
r!   r   c                 8    [        U S[        R                  5      $ )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hkk22r!   c                 8    [        U S[        R                  5      $ )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3r!   c                 8    [        U S[        R                  5      $ )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    [        U S[        R                  5      $ )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                   .    \ rS rSr\" 5       rS rS rSrg)_MaxLengthValidatori  c           	          [        U5      U R                  :  a7  [        SR                  UR                  U R                  [        U5      S95      eg)r,   z*Length of '{name}' must be <= {max}: {len})r-   maxlenN)r   
max_lengthrM   r3   r-   r5   s       r    r9   _MaxLengthValidator.__call__  M     u:'<CCSZ D   (r!   c                 4    SR                  U R                  S9$ )Nz<max_len validator for {max}>)r   )r3   r   r=   s    r    r>   _MaxLengthValidator.__repr__&      .55$//5JJr!   r#   N)	r@   rA   rB   rC   r	   r   r9   r>   rD   r#   r!   r    r   r         J	Kr!   r   c                     [        U 5      $ )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   *       v&&r!   c                   .    \ rS rSr\" 5       rS rS rSrg)_MinLengthValidatori6  c           	          [        U5      U R                  :  a7  [        SR                  UR                  U R                  [        U5      S95      eg)r,   z*Length of '{name}' must be => {min}: {len})r-   minr   N)r   
min_lengthrM   r3   r-   r5   s       r    r9   _MinLengthValidator.__call__:  r   r!   c                 4    SR                  U R                  S9$ )Nz<min_len validator for {min}>)r   )r3   r   r=   s    r    r>   _MinLengthValidator.__repr__E  r   r!   r#   N)	r@   rA   rB   rC   r	   r   r9   r>   rD   r#   r!   r    r   r   6  r   r!   r   c                     [        U 5      $ )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   I  r   r!   )r   Nrt   )0__doc__r   rX   
contextlibr   _configr   r   _maker   r   r	   r
   
exceptionsr   r_   AttributeErrorr.   r`   __all__r   r   r   r)   r   rH   r   rf   r   rq   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r#   r!   r    <module>r      s?  
  	 % ; 5 5 (#jjG
,%$	$ ! !" ED)
 
 *
6&  E$d+
 
 ,
2-4` ED)
 
 *
0)" ED)
 
 *
)$ ED)
 
 *
2!, ET*) ) +)*" ED)
 
 *
>?" ED)E E *E,K  E$d+
 
 ,
2	3	4	4	3 E$d+K K ,K$	' E$d+K K ,K$	'k  #2::b>"G#s   E" "FF