� u��gNN��h�dZddlZddlZddlmZddlmZddlmZmZddl m Z m Z m 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>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���Gd-�d.����Z)d/�Z*e ddd���Gd0�d1����Z+d2�Z,e ddd���Gd3�d4����Z-d5�Z.e ddd���Gd6�d7����Z/de0e1fd8�d9�Z2e ddd���Gd:�d;����Z3d<�Z4dS)?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| ��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)rs �_/home/asafur/pinokio/api/open-webui.git/app/env/lib/python3.11/site-packages/attr/validators.pyrr*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"rr<s��"�#�#� #�#r#c#�xK�td�� dV�td��dS#td��wxYw)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"rrHsM�����u����!� �����4� � � � � ���4� � � � ���s�(�9FT)�repr�slots� unsafe_hashc�.�eZdZe��Zd�Zd�ZdS)�_InstanceOfValidatorc ��t||j��s5d|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�msgs r"�__call__z_InstanceOfValidator.__call__^sr���%���+�+� �g�d�i�g�g�4�9�g�g�e�g�g�RW�Ra�g�g�g�C����� �� �� � � r#c��d|j�d�S)Nz <instance_of validator for type �>�r3�r8s r"�__repr__z_InstanceOfValidator.__repr__k���@�$�)�@�@�@�@r#N��__name__� __module__� __qualname__r r3r=rBr%r#r"r+r+Z�B������ �6�8�8�D� � � �A�A�A�A�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). 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+r@s r"rro��� �� %� %�%r#)r'�frozenr(c�B�eZdZe��Ze��Zd�Zd�ZdS)�_MatchesReValidatorc��|�|��s2d|j�d|jj�d|�d�}t|||j|���dS)r-r.z' must match regex z (z doesn't)N)� match_funcr4�pattern� ValueErrorr7s r"r=z_MatchesReValidator.__call__�si�����u�%�%� �`�d�i�`�`�D�L�4H�`�`�e�`�`�`�C����� �� �� � � r#c��d|j�d�S)Nz"<matches_re validator for pattern r?)rPrAs r"rBz_MatchesReValidator.__repr__�s��E�D�L�E�E�E�Er#N)rErFrGr rPrOr=rBr%r#r"rMrM�sM�������f�h�h�G�����J� � � �F�F�F�F�Fr#rMc ��tjdtjtjf}||vr[d�d�t d�t|��D��������}t|���t|t��r|rd}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*. 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, c3�,K�|]}|r|jpdV��dS)�NoneN)rE)�.0�es r"� <genexpr>zmatches_re.<locals>.<genexpr>�s.����N�N���(�a�j�3�V�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�setrQr2rr6�compilerM)�regex�flags�func� valid_funcsr<rPrOs r"rr�s��*�<��r�y�"�(�;�K� �;���)�0�0� �I�I��N�N�S��=M�=M�N�N�N�N�N� � � � �� ��o�o���%��!�!�+� � !�f�C��C�.�.� �����*�U�E�*�*�� �r�x����]� � � ��� � ��^� � ��&� � �w� � 3� 3�3r#c�.�eZdZe��Zd�Zd�ZdS)�_OptionalValidatorc�<�|�dS|�|||��dS�N�� validator�r8r9r:r;s r"r=z_OptionalValidator.__call__�s(�� �=� �F� ���t�T�5�)�)�)�)�)r#c��d|j�d�S)Nz<optional validator for z or None>rjrAs r"rBz_OptionalValidator.__repr__�s��E�$�.�E�E�E�Er#N)rErFrGr rkr=rBr%r#r"rgrg�sB����������I�*�*�*� F�F�F�F�Fr#rgc��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. )r2�list�tuplergrrjs r"rr�s>���)�d�E�]�+�+�<�!�-� �":�":�;�;�;� �i� (� (�(r#c�F�eZdZe��Zed���Zd�Zd�ZdS)� _InValidatorF)�hashc�� ||jv}n#t$rd}YnwxYw|s-d|j�d|j�d|�d�}t |||j|���dS)NFr.z ' must be in r0�))�optionsr6r4�_original_optionsrQ)r8r9r:r;� in_optionsr<s r"r=z_InValidator.__call__�s��� ��$�,�.�J�J��� � � ��J�J�J� ����� �X�d�i�X�X�d�.D�X�X�e�X�X�X�C�����&�� �� � � s � � �c��d|j�d�S)Nz<in_ validator with options r?)rwrAs r"rBz_InValidator.__repr__�s��I�d�.D�I�I�I�Ir#N)rErFrGr rvrwr=rBr%r#r"rrrr�sU�������f�h�h�G���E�*�*�*�� � � �J�J�J�J�Jr#rrc��|}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. )r2ro�dictr`rprr)rv� repr_optionss r"rrs=��8�L��'�D�$��,�-�-�!���.�.�� ��� .� .�.r#c��eZdZd�Zd�ZdS)�_IsCallableValidatorc��t|��s3d}t|�|j||j���|����dS)r-z?'{name}' must be callable (got {value!r} that is a {actual!r}).)r4r;�actual)r<r;N)�callabler r]r4r5)r8r9r:r;�messages r"r=z_IsCallableValidator.__call__&se������ �8� �#��N�N���%���#���� ��� � � r#c��dS)Nz<is_callable validator>r%rAs r"rBz_IsCallableValidator.__repr__6s��(�(r#N)rErFrGr=rBr%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"rr:s�� � !� !�!r#c�~�eZdZee�����Zedee�������Zd�Zd�Z dS)� _DeepIterablerjN��defaultrkc�z�|j�|�|||��|D]}|�|||���dS�r-N��iterable_validator�member_validator)r8r9r:r;�members r"r=z_DeepIterable.__call__QsY�� � "� .� � #� #�D�$�� 6� 6� 6�� 6� 6�F� � !� !�$��f� 5� 5� 5� 5� 6� 6r#c�D�|j�dn d|j��}d|�d|j�d�S)N�� z<deep_iterable validator forz iterables of r?r�)r8�iterable_identifiers r"rBz_DeepIterable.__repr__[sS���&�.� �B�0�T�,�0�0� �  8�+>� 8� 8�!�2� 8� 8� 8� r#) rErFrGr rr�rr�r=rBr%r#r"r�r�Jsw�������v� � � � �6�6�6����������� 7� 7�����6�6�6�  �  �  �  �  r#r�c�l�t|ttf��r t|�}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 )r2rorpr r��r�r�s r"rrgs9���"�T�5�M�2�2�3��!1�2�� �)�+=� >� >�>r#c��eZdZee�����Zee�����Zedee�������Zd�Z d�Z dS)� _DeepMappingrjNr�c��|j�|�|||��|D]6}|�|||��|�||||���7dSr�)�mapping_validator� key_validator�value_validator)r8r9r:r;�keys r"r=z_DeepMapping.__call__�su�� � !� -� � "� "�4��u� 5� 5� 5�� 9� 9�C� � � �t�T�3� /� /� /� � � ��t�U�3�Z� 8� 8� 8� 8� 9� 9r#c�(�d|j�d|j�d�S)Nz,<deep_mapping validator for objects mapping z to r?)r�r�rAs r"rBz_DeepMapping.__repr__�s"��q�d�>P�q�q�X\�Xl�q�q�q�qr#) rErFrGr rr�r�rr�r=rBr%r#r"r�r�{s��������F�[�[�]�]�3�3�3�M��f�{�{�}�}�5�5�5�O���t�x�x� � � � �7N�7N�O�O�O�� 9� 9� 9�r�r�r�r�rr#r�c�$�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 )r�)r�r�r�s r"rr�s��" � ��8I� J� J�Jr#c�V�eZdZe��Ze��Ze��Zd�Zd�ZdS)�_NumberValidatorc��|�||j��s,d|j�d|j�d|j�d|��}t |���dS)r-r.r/r��: N)� compare_func�boundr4� compare_oprQr7s r"r=z_NumberValidator.__call__�s_��� � ��� �3�3� "�R�d�i�R�R�4�?�R�R�T�Z�R�R�5�R�R�C��S�/�/� !� "� "r#c�(�d|j�d|j�d�S)Nz<Validator for x r�r?)r�r�rAs r"rBz_NumberValidator.__repr__�s��B�4�?�B�B�T�Z�B�B�B�Br#N) rErFrGr r�r�r�r=rBr%r#r"r�r��sX������ �F�H�H�E�����J��6�8�8�L�"�"�"�C�C�C�C�Cr#r�c�8�t|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 �<)r��operatorr��vals r"rr���� �C��h�k� 2� 2�2r#c�8�t|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<=)r�r�rr�s r"rr���� �C��x�{� 3� 3�3r#c�8�t|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>=)r�r�rr�s r"rr�r�r#c�8�t|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 r?)r�r�rr�s r"rr�r�r#c�.�eZdZe��Zd�Zd�ZdS)�_MaxLengthValidatorc��t|��|jkr1d|j�d|j�dt|����}t|���dS)r-� Length of 'z ' must be <= r�N)�len� max_lengthr4rQr7s r"r=z_MaxLengthValidator.__call__��R�� �u�:�:��� '� '�W�� �W�W���W�W�3�u�:�:�W�W�C��S�/�/� !� (� 'r#c��d|j�d�S)Nz<max_len validator for r?)r�rAs r"rBz_MaxLengthValidator.__repr__����;���;�;�;�;r#N)rErFrGr r�r=rBr%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"rr��� �v� &� &�&r#c�.�eZdZe��Zd�Zd�ZdS)�_MinLengthValidatorc��t|��|jkr1d|j�d|j�dt|����}t|���dS)r-r�z ' must be >= r�N)r�� min_lengthr4rQr7s r"r=z_MinLengthValidator.__call__r�r#c��d|j�d�S)Nz<min_len validator for r?)r�rAs r"rBz_MinLengthValidator.__repr__r�r#N)rErFrGr r�r=rBr%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*. Args: length (int): Minimum length of the string or iterable .. versionadded:: 22.1.0 )r�r�s r"rrr�r#c�.�eZdZe��Zd�Zd�ZdS)�_SubclassOfValidatorc��t||j��s-d|j�d|j�d|�d�}t|||j|���dS)r-r.z' must be a subclass of r0r1N)� issubclassr3r4r6r7s r"r=z_SubclassOfValidator.__call__0sf���%���+�+� �W�d�i�W�W���W�W�E�W�W�W�C����� �� �� � � r#c��d|j�d�S)Nz <subclass_of validator for type r?r@rAs r"rBz_SubclassOfValidator.__repr__=rCr#NrDr%r#r"r�r�,rHr#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�r@s r"� _subclass_ofr�ArJr#c��eZdZe��Zeed�����Zeeee ��e e ��������Z d�Z d�ZdS)� _NotValidatorzCnot_ validator child '{validator!r}' did not raise a captured error)� converterr�rjc��� |�|||��t|j�|j|j���||j||j���#|j$rYdSwxYw)N�rk� exc_types)rkrQr<r]r�rls r"r=z_NotValidator.__call__bs��� � �N�N�4��u� -� -� -������"�n�"�n� ��������� � � ���~� � � � �D�D� ���s�A� A(�'A(c�(�d|j�d|j�d�S)Nz<not_ validator wrapping z , capturing r?r�rAs r"rBz_NotValidator.__repr__ss��\�4�>�\�\���\�\�\�\r#N)rErFrGr rkr r<rr�� Exceptionrrpr�r=rBr%r#r"r�r�Rs�����������I� �&�!�/� -� � � � � �C� ���-�)�\�)�4�4�*�{�5�1�1� � � ����I����"]�]�]�]�]r#r�)r<r�c�l� t|��}n#t$r|f}YnwxYwt|||��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 )rpr6r�)rkr<r�s r"rrwsN��:!��)�$�$� � �� �!�!�!��L� � � �!���� ��C�� 3� 3�3s �� "�"c�.�eZdZe��Zd�Zd�ZdS)� _OrValidatorc��|jD]"} ||||��dS#t$rY�wxYwd|j�d|��}t|���)NzNone of z satisfied for value )� validatorsr�rQ)r8r9r:r;�vr<s r"r=z_OrValidator.__call__�s}���� � �A� ���$��e�$�$�$������ � � ��� ���� K���J�J��J�J����o�o�s � � (�(c��d|j�d�S)Nz<or validator wrapping r?)r�rAs r"rBz_OrValidator.__repr__�s��=���=�=�=�=r#N)rErFrGr r�r=rBr%r#r"r�r��s=����������J� � � �>�>�>�>�>r#r�c��g}|D]4}|�t|t��r|jn|g���5tt |����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 )�extendr2r�r�rp)r��valsr�s r"rr�sZ��& �D� �J�J�� � � �J�q�,�$?�$?�H�A�L�L�a�S�I�I�I�I� ��d� � � $� $�$r#)rNri)5�__doc__r�rY� contextlibrr�_configrr�_makerr r r � convertersr � exceptionsr �__all__rrrr+rrMrrgrrrrr~rr�rr�rr�rrrrr�rr�rr�r�r�rQr6rr�rr%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?�?�?�?�(��E��4�0�0�0�r�r�r�r�r�r�r�1�0�r�(K�K�K�K�(��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�!4�H��E��4�0�0�0�>�>�>�>�>�>�>�1�0�>�&%�%�%�%�%r#
Memory