%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/attr/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/attr/__pycache__/validators.cpython-312.pyc

�

��e�L��v�dZddlZddlZddlmZddlmZddlmZmZddl	m
Z
mZmZm
Z
ddlmZdd	lmZgd
�Zd�Zd�Zed
��Ze
ddd��Gd�d��Zd�Ze
ddd��Gd�d��Zd=d�Ze
ddd��Gd�d��Zd�Ze
ddd��Gd�d��Zd�Ze
ddd��Gd�d��Zd �Ze
ddd��Gd!�d"��Z d#�Z!e
ddd��Gd$�d%��Z"d>d&�Z#e
ddd��Gd'�d(��Z$d>d)�Z%e
ddd��Gd*�d+��Z&d,�Z'd-�Z(d.�Z)d/�Z*e
ddd��Gd0�d1��Z+d2�Z,e
ddd��Gd3�d4��Z-d5�Z.e
ddd��Gd6�d7��Z/d8�Z0e
ddd��Gd9�d:��Z1de2e3fd;�d<�Z4y)?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|�y)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)rs �1/usr/lib/python3/dist-packages/attr/validators.pyrr+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"rr=s��"�#�#�#r#c#�bK�td�	d��td�y#td�wxYw�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"rrIs)�����u��!�
��4� ���4� �s�/��/�
,�/FT)�repr�slots�hashc�&�eZdZe�Zd�Zd�Zy)�_InstanceOfValidatorc���t||j�sKdj|j|j|j|��}t|||j|��y)�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/�formatr.�	__class__�	TypeError��self�inst�attrr1�msgs     r"�__call__z_InstanceOfValidator.__call___sd���%����+�S�Z�Z��Y�Y��Y�Y�����	[��C�����	�	��	�
�,r#c�"�d|j�d�S)Nz <instance_of validator for type �>�r/�r7s r"�__repr__z_InstanceOfValidator.__repr__q���1�$�)�)��a�@�@r#N��__name__�
__module__�__qualname__r
r/r;r@r%r#r"r+r+[s���8�D��$Ar#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"rru��� ��%�%r#)r'�frozenr(c�4�eZdZe�Ze�Zd�Zd�Zy)�_MatchesReValidatorc��|j|�sJdj|j|jj|��}t	|||j|��y)r-z9'{name}' must match regex {pattern!r} ({value!r} doesn't))r.�patternr1N)�
match_funcr3r.rL�
ValueErrorr6s     r"r;z_MatchesReValidator.__call__�s_�����u�%�M�T�T��Y�Y����(<�(<�E�U��C��������	�
�	&r#c�"�d|j�d�S)Nz"<matches_re validator for pattern r=)rLr?s r"r@z_MatchesReValidator.__repr__�s��3�D�L�L�3C�1�E�Er#N)rCrDrEr
rLrMr;r@r%r#r"rJrJ�s���h�G���J�
�Fr#rJc
��tjdtjtjf}||vrDdj	djt
d�t|�D����}t|��t|t�r|r
d}t|��|}ntj||�}|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*.

    :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, c3�DK�|]}|xr|jxsd���y�w)�NoneN)rC)�.0�es  r"�	<genexpr>zmatches_re.<locals>.<genexpr>�s!����L�a�q�'�Q�Z�Z�1�6�1�L�s� zR'flags' can only be used with a string pattern; pass flags to re.compile() instead)�re�	fullmatch�search�matchr3�join�sorted�setrNr2rr5�compilerJ)�regex�flags�func�valid_funcsr:rLrMs       r"rr�s��� �<�<��r�y�y�"�(�(�;�K��;��)�0�0��I�I��L�3�{�;K�L�L�
�
��
��o���%��!��f�C��C�.� ����*�*�U�E�*���r�x�x���]�]�
�	
����	��^�^�
��&�&�
��w�
�3�3r#c�&�eZdZe�Zd�Zd�Zy)�_ProvidesValidatorc��|jj|�s@dj|j|j|��}t	|||j|��y)r-z<'{name}' must provide {interface!r} which {value!r} doesn't.)r.�	interfacer1N)re�
providedByr3r.r5r6s     r"r;z_ProvidesValidator.__call__�s_���~�~�(�(��/�P�W�W��Y�Y�$�.�.��X��C��������	�
�	0r#c�"�d|j�d�S)Nz"<provides validator for interface r=)rer?s r"r@z_ProvidesValidator.__repr__�s��3�D�N�N�3E�Q�G�Gr#N)rCrDrEr
rer;r@r%r#r"rcrc�s����I�
�Hr#rcc�P�ddl}|jdtd��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�DeprecationWarningrc)rerks  r"rr�s0�� ��M�M�	 ���	���i�(�(r#c�&�eZdZe�Zd�Zd�Zy)�_OptionalValidatorc�0�|�y|j|||�y�N��	validator�r7r8r9r1s    r"r;z_OptionalValidator.__call__�s���=�����t�T�5�)r#c�"�d|j�d�S)Nz<optional validator for z	 or None>rrr?s r"r@z_OptionalValidator.__repr__s��)�$�.�.�);�9�E�Er#N)rCrDrEr
rsr;r@r%r#r"roro�s����I�*�Fr#roc�l�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.

    :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�tuplerorrrs r"rrs-���)�d�E�]�+�!�-�	�":�;�;��i�(�(r#c�&�eZdZe�Zd�Zd�Zy)�_InValidatorc��	||jv}|s8d|j�d|j�d|�d�}t|||j|��y#t$rd}Y�HwxYw)NF�'z
' must be in � (got �))�optionsr5r.rN)r7r8r9r1�
in_optionsr:s      r"r;z_InValidator.__call__su��	��$�,�,�.�J���d�i�i�[�
�d�l�l�-=�V�E�9�A�N�C��������	�
����	��J�	�s�A�A�Ac�"�d|j�d�S)Nz<in_ validator with options r=�rr?s r"r@z_InValidator.__repr__.s��-�d�l�l�-=�Q�?�?r#N)rCrDrEr
rr;r@r%r#r"rzrzs���h�G�
�@r#rzc��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.
    )rzr�s r"rr2s��&�� � r#c��eZdZd�Zd�Zy)�_IsCallableValidatorc��t|�s5d}t|j|j||j��|���y)r-z?'{name}' must be callable (got {value!r} that is a {actual!r}).)r.r1r0)r:r1N)�callabler
r3r.r4)r7r8r9r1�messages     r"r;z_IsCallableValidator.__call__JsN�����8�
�#��N�N����%����#���	�
�r#c��y)Nz<is_callable validator>r%r?s r"r@z_IsCallableValidator.__repr__Zs��(r#N)rCrDrEr;r@r%r#r"r�r�Hs��� )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"rr^s
�� �!�!r#c�^�eZdZee���Zedee����Zd�Zd�Z	y)�
_DeepIterablerrN��defaultrsc�v�|j�|j|||�|D]}|j|||��y�r-N��iterable_validator�member_validator)r7r8r9r1�members     r"r;z_DeepIterable.__call__tsC���"�"�.��#�#�D�$��6��	6�F��!�!�$��f�5�	6r#c�b�|j�dnd|j��}d|�d|j�d�S)N�� z<deep_iterable validator forz iterables of r=r�)r7�iterable_identifiers  r"r@z_DeepIterable.__repr__~sP���&�&�.�
��T�,�,�/�0�	�+�+>�*?��T�2�2�5�Q�
8�	
r#)
rCrDrEr
rr�rr�r;r@r%r#r"r�r�ms0����
�6������� 7���6�	
r#r�c�V�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
    )r2rwrxr	r��r�r�s  r"rr�s.���"�T�5�M�2��!1�2���)�+=�>�>r#c�z�eZdZee���Zee���Zedee����Zd�Z	d�Z
y)�_DeepMappingrrNr�c��|j�|j|||�|D]+}|j|||�|j||||��-yr�)�mapping_validator�
key_validator�value_validator)r7r8r9r1�keys     r"r;z_DeepMapping.__call__�sY���!�!�-��"�"�4��u�5��	9�C����t�T�3�/�� � ��t�U�3�Z�8�	9r#c�P�dj|j|j��S)NzA<deep_mapping validator for objects mapping {key!r} to {value!r}>)r�r1)r3r�r�r?s r"r@z_DeepMapping.__repr__�s%��O�
�&�T�'�'�t�/C�/C�&�
D�	Er#)rCrDrEr
rr�r�rr�r;r@r%r#r"r�r��s9���[�]�3�M��{�}�5�O��t�x��
�7N�O��	9�Er#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"rr�s���
��8I�J�Jr#c�B�eZdZe�Ze�Ze�Zd�Zd�Zy)�_NumberValidatorc��|j||j�s7d|j�d|j�d|j�d|��}t	|��y)r-r|z
' must be r��: N)�compare_func�boundr.�
compare_oprNr6s     r"r;z_NumberValidator.__call__�sR��� � ���
�
�3��d�i�i�[�
�4�?�?�*;�1�T�Z�Z�L��5�'�R�C��S�/�!�4r#c�<�d|j�d|j�d�S)Nz<Validator for x r�r=)r�r�r?s r"r@z_NumberValidator.__repr__�s ��"�4�?�?�"3�1�T�Z�Z�L��B�Br#N)	rCrDrEr
r�r�r�r;r@r%r#r"r�r��s"���H�E���J��8�L�"�Cr#r�c�8�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��vals r"rr�����C��h�k�k�2�2r#c�8�t|dtj�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�rr�s r"rr�����C��x�{�{�3�3r#c�8�t|dtj�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�rr�s r"rr�r�r#c�8�t|dtj�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�rr�s r"rr�r�r#c�&�eZdZe�Zd�Zd�Zy)�_MaxLengthValidatorc��t|�|jkDr3d|j�d|j�dt|���}t|��y)r-�Length of 'z
' must be <= r�N)�len�
max_lengthr.rNr6s     r"r;z_MaxLengthValidator.__call__�H���u�:����'���	�	�{�-����7H��3�u�:�,�W�C��S�/�!�(r#c�"�d|j�d�S)Nz<max_len validator for r=)r�r?s r"r@z_MaxLengthValidator.__repr__���(����(9��;�;r#N)rCrDrEr
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"rr����v�&�&r#c�&�eZdZe�Zd�Zd�Zy)�_MinLengthValidatorc��t|�|jkr3d|j�d|j�dt|���}t|��y)r-r�z
' must be >= r�N)r��
min_lengthr.rNr6s     r"r;z_MinLengthValidator.__call__$r�r#c�"�d|j�d�S)Nz<min_len validator for r=)r�r?s r"r@z_MinLengthValidator.__repr__,r�r#N)rCrDrEr
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"rr0r�r#c�&�eZdZe�Zd�Zd�Zy)�_SubclassOfValidatorc��t||j�s8d|j�d|j�d|�d�}t|||j|��y)r-r|z' must be a subclass of r}z).N)�
issubclassr/r.r5r6s     r"r;z_SubclassOfValidator.__call__@sX���%����+��d�i�i�[� 8����
�V�E�9�TV�W�C�����	�	��	�
�,r#c�"�d|j�d�S)Nz <subclass_of validator for type r=r>r?s r"r@z_SubclassOfValidator.__repr__MrAr#NrBr%r#r"r�r�<s���8�D��Ar#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�QrGr#c�~�eZdZe�Zeed���Zeeee	�e
e�����Zd�Z
d�Zy)�
_NotValidatorzCnot_ validator child '{validator!r}' did not raise a captured error)�	converterr�rrc��	|j|||�t|jj|j|j��||j||j��#|j$rYywxYw)N)rs�	exc_types)rsrNr:r3r�rts    r"r;z_NotValidator.__call__qsw��	��N�N�4��u�-�������"�n�n�"�n�n� ����������	�	
���~�~�	��	�s�A'�'A9�8A9c�P�dj|j|j��S)Nz;<not_ validator wrapping {what!r}, capturing {exc_types!r}>)�whatr�)r3rsr�r?s r"r@z_NotValidator.__repr__�s'��I�
�&�����n�n��
�	
r#N)rCrDrEr
rsrr:rr��	Exceptionrrxr�r;r@r%r#r"r�r�asN����I�
�!�
-�
��C���)�)�4�*�5�1�
��I��"
r#r�)r:r�c�X�	t|�}t|||�S#t$r|f}Y�wxYw)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
    )rxr5r�)rsr:r�s   r"rr�s:��4!��)�$�	���C��3�3���!��L�	�!�s��)�))rNrq)5�__doc__r�rV�
contextlibrr�_configrr�_makerr	r
r�
convertersr�
exceptionsr
�__all__rrrr+rrJrrcrrorrzrr�rr�rr�rr�rrrrr�rr�rr�r�r�rNr5rr%r#r"�<module>r�s}���
�	�%��;�5�5�'�(���.%�$	$��!��!�"�E��D�)�A�A�*�A�2
&� �E�$�d�+�F�F�,�F�.(4�V�E��D�)�H�H�*�H�,)�6�E��D�)�
F�
F�*�
F�)�&�E��D�)�@�@�*�@�,!�,�E��T�*�)�)�+�)�*"��E��D�)�
�
�*�
�8?�"�E��D�)�E�E�*�E�,
K� �E�$�d�+�C�C�,�C�"	3�	4�	4�	3��E�$�d�+�<�<�,�<�	'��E�$�d�+�<�<�,�<�	'��E��D�)�A�A�*�A�(
&� �E��D�)�&
�&
�*�&
�R �J�	�+B�4r#

Zerion Mini Shell 1.0