HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/attr/__pycache__/validators.cpython-310.pyc
o

"we�P�@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 d+d,�Z!e
dddd�Gd-d.�d.��Z"dQd/d0�Z#e
dddd�Gd1d2�d2��Z$dQd3d4�Z%e
dddd�Gd5d6�d6��Z&d7d8�Z'd9d:�Z(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/dIdJ�Z0e
dddd�GdKdL�dL��Z1de2e3fdM�dNdO�Z4dS)Rz
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_disabledcCst|�dS)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�r �H/home/arjun/projects/env/lib/python3.10/site-packages/attr/validators.pyr+srcCst�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
    )rr r r r!r=�	rccs*�td�z
dVWtd�dStd�w)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!rIs
�rFT)�repr�slots�hashc@�"eZdZe�Zdd�Zdd�ZdS)�_InstanceOfValidatorcCs4t||j�stdj|j|j|j|d�||j|��dS)�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�attrr,r r r!�__call___s���z_InstanceOfValidator.__call__cC�dj|jd�S)Nz)<instance_of validator for type {type!r}>�r*�r/r*�r2r r r!�__repr__q��z_InstanceOfValidator.__repr__N��__name__�
__module__�__qualname__r	r*r5r:r r r r!r'[sr'cC�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'r7r r r!rw�
r)r#�frozenr$c@s(eZdZe�Ze�Zdd�Zdd�ZdS)�_MatchesReValidatorcCs0|�|�stdj|j|jj|d�||j|��dS)r(z9'{name}' must match regex {pattern!r} ({value!r} doesn't))r)�patternr,N)�
match_func�
ValueErrorr/r)rDr1r r r!r5�s
���z_MatchesReValidator.__call__cCr6)Nz.<matches_re validator for pattern {pattern!r}>)rD)r/rDr9r r r!r:�r;z_MatchesReValidator.__repr__N)r=r>r?r	rDrEr5r:r r r r!rC�s
rCc	Cs�tjdtjtjf}||vr td�d�tdd�t|�D������t	|t
�r.|r+td��|}nt�||�}|tjur=|j}n|tjurF|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, css�|]
}|r	|jp
dVqdS)�NoneN)r=)�.0�er r r!�	<genexpr>�s�
�zmatches_re.<locals>.<genexpr>zR'flags' can only be used with a string pattern; pass flags to re.compile() instead)�re�	fullmatch�search�matchrFr/�join�sorted�setr-rr.�compilerC)�regex�flags�func�valid_funcsrDrEr r r!r�s0����

�


rc@r&)�_ProvidesValidatorcCs0|j�|�stdj|j|j|d�||j|��dS)r(z<'{name}' must provide {interface!r} which {value!r} doesn't.)r)�	interfacer,N)rX�
providedByr.r/r)r1r r r!r5�s
���z_ProvidesValidator.__call__cCr6)Nz0<provides validator for interface {interface!r}>)rX)r/rXr9r r r!r:�r;z_ProvidesValidator.__repr__N)r=r>r?r	rXr5r:r r r r!rW�srWcCs ddl}|jdtdd�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
    rNzZattrs's zope-interface support is deprecated and will be removed in, or after, April 2024.�)�
stacklevel)�warnings�warn�DeprecationWarningrW)rXr\r r r!r�s�rc@r&)�_OptionalValidatorcCs|durdS|�|||�dS�N��	validatorr1r r r!r5	sz_OptionalValidator.__call__cCsdjt|j�d�S)Nz'<optional validator for {what} or None>)�what)r/r#rbr9r r r!r:��z_OptionalValidator.__repr__N)r=r>r?r	rbr5r:r r r r!r_sr_cCs"t|ttf�r
tt|��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.

    :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.
    )r-�list�tupler_rrar r r!rs
rc@r&)�_InValidatorcCsNz||jv}Wntyd}Ynw|s%tdj|j|j|d�||j|��dS)NFz/'{name}' must be in {options!r} (got {value!r}))r)�optionsr,)rhr.rFr/r))r2r3r4r,�
in_optionsr r r!r5,s�
���z_InValidator.__call__cCr6)Nz(<in_ validator with options {options!r}>�rh)r/rhr9r r r!r:<r;z_InValidator.__repr__N)r=r>r?r	rhr5r:r r r r!rg(srgcCr@)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.
    )rgrjr r r!rBsrc@seZdZdd�Zdd�ZdS)�_IsCallableValidatorcCs,t|�sd}t|j|j||jd�|d��dS)r(z?'{name}' must be callable (got {value!r} that is a {actual!r}).)r)r,r+)�msgr,N)�callablerr/r)r0)r2r3r4r,�messager r r!r5Zs�
���z_IsCallableValidator.__call__cCsdS)Nz<is_callable validator>r r9r r r!r:jsz_IsCallableValidator.__repr__N)r=r>r?r5r:r r r r!rkXsrkcCst�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.
    )rkr r r r!rnsrc@s:eZdZee�d�Zedee��d�Zdd�Zdd�Z	dS)�
_DeepIterableraN��defaultrbcCs4|jdur|�|||�|D]	}|�|||�qdS�r(N)�iterable_validator�member_validator)r2r3r4r,�memberr r r!r5�s

�z_DeepIterable.__call__cCs*|jdurdnd|j��}dj||jd�S)N�� zJ<deep_iterable validator for{iterable_identifier} iterables of {member!r}>)�iterable_identifierru)rsr/rt)r2rxr r r!r:�s
�
��z_DeepIterable.__repr__)
r=r>r?r	rrtrrsr5r:r r r r!ro}s
�
rocCs t|ttf�rt|�}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
    )r-rerfrro�rtrsr r r!r
�s
r
c@sFeZdZee�d�Zee�d�Zedee��d�Zdd�Z	dd�Z
dS)�_DeepMappingraNrpcCsF|jdur|�|||�|D]}|�|||�|�||||�qdSrr)�mapping_validator�
key_validator�value_validator)r2r3r4r,�keyr r r!r5�s
�z_DeepMapping.__call__cC�dj|j|jd�S)NzA<deep_mapping validator for objects mapping {key!r} to {value!r}>)r~r,)r/r|r}r9r r r!r:�s
�z_DeepMapping.__repr__)r=r>r?r	rr|r}rr{r5r:r r r r!rz�srzcCs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
    )rz)r|r}r{r r r!r�s
rc@s.eZdZe�Ze�Ze�Zdd�Zdd�ZdS)�_NumberValidatorcCs.|�||j�stdj|j|j|j|d���dS)r(z&'{name}' must be {op} {bound}: {value})r)�op�boundr,N)�compare_funcr�rFr/r)�
compare_opr1r r r!r5�s���z_NumberValidator.__call__cCr)Nz<Validator for x {op} {bound}>)r�r�)r/r�r�r9r r r!r:�rdz_NumberValidator.__repr__N)	r=r>r?r	r�r�r�r5r:r r r r!r��sr�cC�t|dtj�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��valr r r!r��	rcCr�)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�rr�r r r!r�r�rcCr�)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�rr�r r r!rr�rcCr�)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�rr�r r r!rr�rc@r&)�_MaxLengthValidatorcCs.t|�|jkrtdj|j|jt|�d���dS)r(z*Length of '{name}' must be <= {max}: {len})r)�max�lenN)r��
max_lengthrFr/r)r1r r r!r5#����z_MaxLengthValidator.__call__cC�d|j�d�S)Nz<max_len validator for r�)r�r9r r r!r:.�z_MaxLengthValidator.__repr__N)r=r>r?r	r�r5r:r r r r!r��r�cCr@)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���lengthr r r!r2r"rc@r&)�_MinLengthValidatorcCs.t|�|jkrtdj|j|jt|�d���dS)r(z*Length of '{name}' must be => {min}: {len})r)�minr�N)r��
min_lengthrFr/r)r1r r r!r5Br�z_MinLengthValidator.__call__cCr�)Nz<min_len validator for r�)r�r9r r r!r:Mr�z_MinLengthValidator.__repr__N)r=r>r?r	r�r5r:r r r r!r�>r�r�cCr@)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�r r r!rQr"rc@r&)�_SubclassOfValidatorcCs0t||j�stdj|j|j|d�||j|��dS)r(z8'{name}' must be a subclass of {type!r} (got {value!r}).)r)r*r,N)�
issubclassr*r.r/r)r1r r r!r5as���z_SubclassOfValidator.__call__cCr6)Nz)<subclass_of validator for type {type!r}>r7r8r9r r r!r:rr;z_SubclassOfValidator.__repr__Nr<r r r r!r�]sr�cCr@)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�r7r r r!�_subclass_ofxrAr�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)�	converterryracCsNz	|�|||�Wn|jyYdSwt|jj|j|jd�||j||j��)N)rb�	exc_types)rbr�rFrlr/r1r r r!r5�s���z_NotValidator.__call__cCr)Nz;<not_ validator wrapping {what!r}, capturing {exc_types!r}>)rcr�)r/rbr�r9r r r!r:�s
�z_NotValidator.__repr__N)r=r>r?r	rbrrlr
r��	Exceptionrrfr�r5r:r r r r!r��s����r�)rlr�cCs2zt|�}Wnty|f}Ynwt|||�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
    )rfr.r�)rbrlr�r r r!r�s
�r)rNr`)5�__doc__r�rK�
contextlibrr�_configrr�_makerrr	r
�
convertersr�
exceptionsr�__all__rrrr'rrCrrWrr_rrgrrkrror
rzrr�rrrrr�rr�rr�r�r�rFr.rr r r r!�<module>sp

0

)