HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/attr/__pycache__/validators.cpython-39.pyc
a

�,�hNN�@s�dZddlZddlZddlmZddlmZddlmZmZddl	m
Z
mZmZm
Z
ddlmZdd	lmZgd
�Zdd�Zd
d�Zedd��Ze
dddd�Gdd�d��Zdd�Ze
dddd�Gdd�d��ZdPdd�Ze
dddd�Gdd�d��Zdd �Ze
dddd�Gd!d"�d"��Zd#d$�Ze
dddd�Gd%d&�d&��Zd'd(�Ze
dddd�Gd)d*�d*��Z dQd+d,�Z!e
dddd�Gd-d.�d.��Z"dRd/d0�Z#e
dddd�Gd1d2�d2��Z$d3d4�Z%d5d6�Z&d7d8�Z'd9d:�Z(e
dddd�Gd;d<�d<��Z)d=d>�Z*e
dddd�Gd?d@�d@��Z+dAdB�Z,e
dddd�GdCdD�dD��Z-dEdF�Z.e
dddd�GdGdH�dH��Z/de0e1fdI�dJdK�Z2e
dddd�GdLdM�dM��Z3dNdO�Z4dS)Sz
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_disabledcCst|�dS)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�r �@/opt/nydus/tmp/pip-target-wkfpz8uv/lib/python/attr/validators.pyr*srcCst�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
    )rr r r r!r<s	rccs*td�zdVWtd�n
td�0dS)z�
    Context manager that disables running validators within its context.

    .. warning::

        This context manager is not thread-safe!

    .. versionadded:: 21.3.0
    FNTrr r r r!rHsrFT)�repr�slotsZunsafe_hashc@s"eZdZe�Zdd�Zdd�ZdS)�_InstanceOfValidatorc	CsDt||j�s@d|j�d|j�d|�d|j�d�	}t|||j|��dS)�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�msgr r r!�__call__^s$�z_InstanceOfValidator.__call__cCsd|j�d�S)Nz <instance_of validator for type �>�r+�r0r r r!�__repr__ksz_InstanceOfValidator.__repr__N��__name__�
__module__�__qualname__r	r+r5r9r r r r!r$Zs
r$cCst|�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$r7r r r!rosr)r"�frozenr#c@s(eZdZe�Ze�Zdd�Zdd�ZdS)�_MatchesReValidatorcCs<|�|�s8d|j�d|jj�d|�d�}t|||j|��dS)r%r&z' must match regex z (z	 doesn't)N)�
match_funcr,�pattern�
ValueErrorr/r r r!r5�s
�z_MatchesReValidator.__call__cCsd|j�d�S)Nz"<matches_re validator for pattern r6)rAr8r r r!r9�sz_MatchesReValidator.__repr__N)r;r<r=r	rAr@r5r9r r r r!r?�s
r?cCs�tjdtjtjf}||vrDd�d�tdd�t|�D����}t|��t	|t
�rd|r^d}t|��|}nt�||�}|tjur�|j}n|tjur�|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, css|]}|r|jpdVqdS)�NoneN)r;)�.0�er r r!�	<genexpr>��zmatches_re.<locals>.<genexpr>zR'flags' can only be used with a string pattern; pass flags to re.compile() instead)�re�	fullmatch�search�match�format�join�sorted�setrBr*rr.�compiler?)�regex�flags�funcZvalid_funcsr4rAr@r r r!r�s(��


rc@s"eZdZe�Zdd�Zdd�ZdS)�_OptionalValidatorcCs|durdS|�|||�dS)N��	validator�r0r1r2r3r r r!r5�sz_OptionalValidator.__call__cCsd|j�d�S)Nz<optional validator for z	 or None>rUr8r r r!r9�sz_OptionalValidator.__repr__N)r;r<r=r	rVr5r9r r r r!rT�srTcCs"t|ttf�rtt|��St|�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.
    )r*�list�tuplerTrrUr r r!r�src@s,eZdZe�Zedd�Zdd�Zdd�ZdS)�_InValidatorF)�hashcCsZz||jv}Wnty$d}Yn0|sVd|j�d|j�d|�d�}t|||j|��dS)NFr&z
' must be in r(�))�optionsr.r,�_original_optionsrB)r0r1r2r3Z
in_optionsr4r r r!r5�s
�z_InValidator.__call__cCsd|j�d�S)Nz<in_ validator with options r6)r^r8r r r!r9�sz_InValidator.__repr__N)r;r<r=r	r]r^r5r9r r r r!rZ�s
rZcCs&|}t|tttf�rt|�}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.
    )r*rX�dictrOrYrZ)r]Zrepr_optionsr r r!rsrc@seZdZdd�Zdd�ZdS)�_IsCallableValidatorcCs,t|�s(d}t|j|j||jd�|d��dS)r%z?'{name}' must be callable (got {value!r} that is a {actual!r}).)r,r3�actual)r4r3N)�callablerrLr,r-)r0r1r2r3�messager r r!r5&s�
��z_IsCallableValidator.__call__cCsdS)Nz<is_callable validator>r r8r r r!r96sz_IsCallableValidator.__repr__N)r;r<r=r5r9r r r r!r`$sr`cCst�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
rc@s:eZdZee�d�Zedee��d�Zdd�Zdd�Z	dS)�
_DeepIterablerUN��defaultrVcCs4|jdur|�|||�|D]}|�|||�qdS�r%N��iterable_validator�member_validator)r0r1r2r3�memberr r r!r5Qs
z_DeepIterable.__call__cCs.|jdurdn
d|j��}d|�d|j�d�S)N�� z<deep_iterable validator forz iterables of r6rh)r0Ziterable_identifierr r r!r9[s�
���z_DeepIterable.__repr__)
r;r<r=r	rrjrrir5r9r r r r!rdJs
�
rdcCs t|ttf�rt|�}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
    )r*rXrYrrd�rjrir r r!r
gsr
c@sFeZdZee�d�Zee�d�Zedee��d�Zdd�Z	dd�Z
dS)�_DeepMappingrUNrecCsF|jdur|�|||�|D]$}|�|||�|�||||�qdSrg)�mapping_validator�
key_validator�value_validator)r0r1r2r3�keyr r r!r5�s

z_DeepMapping.__call__cCsd|j�d|j�d�S)Nz,<deep_mapping validator for objects mapping z to r6)rqrrr8r r r!r9�sz_DeepMapping.__repr__)r;r<r=r	rrqrrrrpr5r9r r r r!ro{s
rocCs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
    )ro)rqrrrpr r r!r�src@s.eZdZe�Ze�Ze�Zdd�Zdd�ZdS)�_NumberValidatorcCs<|�||j�s8d|j�d|j�d|j�d|��}t|��dS)r%r&r'rm�: N)�compare_func�boundr,�
compare_oprBr/r r r!r5�s"z_NumberValidator.__call__cCsd|j�d|j�d�S)Nz<Validator for x rmr6)rxrwr8r r r!r9�sz_NumberValidator.__repr__N)	r;r<r=r	rwrxrvr5r9r r r r!rt�s
rtcCst|dtj�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
    �<)rt�operatorr��valr r r!r�srcCst|dtj�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<=)rtrzrr{r r r!r�srcCst|dtj�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>=)rtrzrr{r r r!r�srcCst|dtj�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
    r6)rtrzrr{r r r!r�src@s"eZdZe�Zdd�Zdd�ZdS)�_MaxLengthValidatorcCs8t|�|jkr4d|j�d|j�dt|���}t|��dS)r%�Length of 'z
' must be <= ruN)�len�
max_lengthr,rBr/r r r!r5�sz_MaxLengthValidator.__call__cCsd|j�d�S)Nz<max_len validator for r6)r�r8r r r!r9�sz_MaxLengthValidator.__repr__N)r;r<r=r	r�r5r9r r r r!r}�sr}cCst|�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}��lengthr r r!rs
rc@s"eZdZe�Zdd�Zdd�ZdS)�_MinLengthValidatorcCs8t|�|jkr4d|j�d|j�dt|���}t|��dS)r%r~z
' must be >= ruN)r�
min_lengthr,rBr/r r r!r5sz_MinLengthValidator.__call__cCsd|j�d�S)Nz<min_len validator for r6)r�r8r r r!r9sz_MinLengthValidator.__repr__N)r;r<r=r	r�r5r9r r r r!r�sr�cCst|�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�r r r!rs
rc@s"eZdZe�Zdd�Zdd�ZdS)�_SubclassOfValidatorcCs<t||j�s8d|j�d|j�d|�d�}t|||j|��dS)r%r&z' must be a subclass of r(r)N)�
issubclassr+r,r.r/r r r!r50s�z_SubclassOfValidator.__call__cCsd|j�d�S)Nz <subclass_of validator for type r6r7r8r r r!r9=sz_SubclassOfValidator.__repr__Nr:r r r r!r�,s
r�cCst|�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�r7r r r!�_subclass_ofAsr�c@sJeZdZe�Zeed�d�Zeeee	�e
e�d�d�Zdd�Z
dd�Zd	S)
�
_NotValidatorzCnot_ validator child '{validator!r}' did not raise a captured error)�	converterrnrUcCsPz|�|||�Wn|jy&Yn&0t|jj|j|jd�||j||j��dS)N�rV�	exc_types)rVr�rBr4rLrWr r r!r5bs��z_NotValidator.__call__cCsd|j�d|j�d�S)Nz<not_ validator wrapping z, capturing r6r�r8r r r!r9ssz_NotValidator.__repr__N)r;r<r=r	rVrr4r
r��	ExceptionrrYr�r5r9r r r r!r�Rs����r�)r4r�cCs2zt|�}Wnty$|f}Yn0t|||�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
    )rYr.r�)rVr4r�r r r!rws
rc@s"eZdZe�Zdd�Zdd�ZdS)�_OrValidatorc	CsX|jD]2}z||||�Wnty0YqYq0dSqd|j�d|��}t|��dS)NzNone of z satisfied for value )�
validatorsr�rB)r0r1r2r3�vr4r r r!r5�s

z_OrValidator.__call__cCsd|j�d�S)Nz<or validator wrapping r6)r�r8r r r!r9�sz_OrValidator.__repr__N)r;r<r=r	r�r5r9r r r r!r��sr�cGs6g}|D] }|�t|t�r |jn|g�qtt|��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
    )�extendr*r�r�rY)r��valsr�r r r!r�sr)rN)N)N)5�__doc__rzrH�
contextlibrr�_configrr�_makerrr	r
�
convertersr�
exceptionsr�__all__rrrr$rr?rrTrrZrr`rrdr
rorrtrrrrr}rr�rr�r�r�rBr.rr�rr r r r!�<module>sn

0
#



$$