OwlCyberSecurity - MANAGER
Edit File: validators.cpython-37.pyc
B ����^u_�,��������������� ���@���s���d�Z�ddlmZmZmZ�ddlZddlmZmZm Z m Z �ddlmZ�ddd d ddd ddg Z e dddd�G�dd��de��Zdd��Ze dddd�G�dd��de��Zd,dd �Ze dddd�G�dd��de��Zdd��Ze dddd�G�dd��de��Zdd��Ze dddd�G�d d!��d!e��Zd"d ��Ze dddd�G�d#d$��d$e��Zd%d��Ze dddd�G�d&d'��d'e��Zd-d(d�Ze dddd�G�d)d*��d*e��Zd.d+d �ZdS�)/z Commonly useful validators. �����)�absolute_import�division�print_functionN����)� _AndValidator�and_�attrib�attrs)�NotCallableErrorr���� deep_iterable�deep_mapping�in_�instance_of�is_callable� matches_re�optional�providesFT)�repr�slots�hashc���������������@���s"���e�Zd�Ze��Zdd��Zdd��ZdS�)�_InstanceOfValidatorc�������������C���s4���t�||�j�s0tdj|j|�j|j|d�||�j|��dS�)zP 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"����@/opt/alt/python37/lib/python3.7/site-packages/attr/validators.py�__call__���s����z_InstanceOfValidator.__call__c�������������C���s���dj�|�jd�S�)Nz)<instance_of validator for type {type!r}>)r���)r���r���)r���r"���r"���r#����__repr__0���s����z_InstanceOfValidator.__repr__N)�__name__� __module__�__qualname__r���r���r$���r%���r"���r"���r"���r#���r������s���r���c�������������C���s���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 types :raises TypeError: With a human readable error message, the attribute (of type `attr.Attribute`), the expected type, and the value it got. )r���)r���r"���r"���r#���r���6���s���� )r����frozenr���c���������������@���s.���e�Zd�Ze��Ze��Ze��Zdd��Zdd��ZdS�)�_MatchesReValidatorc�������������C���s0���|���|�s,tdj|j|�jj|d�||�j|��dS�)zP We use a callable class to be able to change the ``__repr__``. z7'{name}' must match regex {regex!r} ({value!r} doesn't))r����regexr���N)� match_func� ValueErrorr���r���r+����pattern)r���r ���r!���r���r"���r"���r#���r$���L���s���� z_MatchesReValidator.__call__c�������������C���s���dj�|�jd�S�)Nz,<matches_re validator for pattern {regex!r}>)r+���)r���r+���)r���r"���r"���r#���r%���[���s����z_MatchesReValidator.__repr__N) r&���r'���r(���r���r+����flagsr,���r$���r%���r"���r"���r"���r#���r*���F���s ���r*���c�������������C���s����t�tdd�}|dtjtjf}||krJtdd�tdd��t|�D����f���t�|�|�}|tjkrh|j}n6|tjkrz|j}n$|r�|j }nt�d� |��|�}|j}t|||�S�)a}�� A validator that raises `ValueError` if the initializer is called with a string that doesn't match *regex*. :param str regex: a regex string 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 (options are `re.fullmatch`, `re.search`, `re.match`, default is ``None`` which means either `re.fullmatch` or an emulation of it on Python 2). For performance reasons, they won't be used directly but on a pre-`re.compile`\ ed pattern. .. versionadded:: 19.2.0 � fullmatchNz'func' must be one of %s.z, c�������������s���s���|�]}|r|j�pd�V��qdS�)�NoneN)r&���)�.0�er"���r"���r#���� <genexpr>y���s����zmatches_re.<locals>.<genexpr>z(?:{})\Z)�getattr�re�search�matchr-����join�sorted�set�compiler0���r���r*���)r+���r/����funcr0���Zvalid_funcsr.���r,���r"���r"���r#���r���a���s$���� c���������������@���s"���e�Zd�Ze��Zdd��Zdd��ZdS�)�_ProvidesValidatorc�������������C���s0���|�j��|�s,tdj|j|�j�|d�||�j�|��dS�)zP We use a callable class to be able to change the ``__repr__``. z<'{name}' must provide {interface!r} which {value!r} doesn't.)r���� interfacer���N)r?���Z providedByr���r���r���)r���r ���r!���r���r"���r"���r#���r$�������s����z_ProvidesValidator.__call__c�������������C���s���dj�|�jd�S�)Nz0<provides validator for interface {interface!r}>)r?���)r���r?���)r���r"���r"���r#���r%�������s����z_ProvidesValidator.__repr__N)r&���r'���r(���r���r?���r$���r%���r"���r"���r"���r#���r>�������s���r>���c�������������C���s���t�|��S�)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 `attr.Attribute`), the expected interface, and the value it got. )r>���)r?���r"���r"���r#���r�������s����c���������������@���s"���e�Zd�Ze��Zdd��Zdd��ZdS�)�_OptionalValidatorc�������������C���s���|d�krd�S�|���|||��d�S�)N)� validator)r���r ���r!���r���r"���r"���r#���r$�������s����z_OptionalValidator.__call__c�������������C���s���dj�t|�j�d�S�)Nz'<optional validator for {what} or None>)�what)r���r���rA���)r���r"���r"���r#���r%�������s����z_OptionalValidator.__repr__N)r&���r'���r(���r���rA���r$���r%���r"���r"���r"���r#���r@�������s���r@���c�������������C���s���t�|�t�rtt|���S�t|��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 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. )r����listr@���r���)rA���r"���r"���r#���r�������s���� c���������������@���s"���e�Zd�Ze��Zdd��Zdd��ZdS�)�_InValidatorc�������������C���sH���y||�j�k}W�n�tk r&���d}Y�nX�|sDtdj|j|�j�|d���d�S�)NFz/'{name}' must be in {options!r} (got {value!r}))r����optionsr���)rE���r���r-���r���r���)r���r ���r!���r���Z in_optionsr"���r"���r#���r$�������s���� z_InValidator.__call__c�������������C���s���dj�|�jd�S�)Nz(<in_ validator with options {options!r}>)rE���)r���rE���)r���r"���r"���r#���r%�������s����z_InValidator.__repr__N)r&���r'���r(���r���rE���r$���r%���r"���r"���r"���r#���rD�������s��� rD���c�������������C���s���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 `attr.Attribute`), the expected options, and the value it got. .. versionadded:: 17.1.0 )rD���)rE���r"���r"���r#���r �������s����c���������������@���s���e�Zd�Zdd��Zdd��ZdS�)�_IsCallableValidatorc�������������C���s,���t�|�s(d}t|j|j||jd�|d��dS�)zP We use a callable class to be able to change the ``__repr__``. z?'{name}' must be callable (got {value!r} that is a {actual!r}).)r���r���r���)�msgr���N)�callabler ���r���r���r���)r���r ���r!���r����messager"���r"���r#���r$�����s����z_IsCallableValidator.__call__c�������������C���s���dS�)Nz<is_callable validator>r"���)r���r"���r"���r#���r%�����s����z_IsCallableValidator.__repr__N)r&���r'���r(���r$���r%���r"���r"���r"���r#���rF�����s���rF���c���������������C���s���t���S�)aw�� 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 (`attr.Attribute`) name, and the value it got. )rF���r"���r"���r"���r#���r�����s����c���������������@���s:���e�Zd�Zee��d�Zedee���d�Zdd��Zdd��Z dS�)� _DeepIterable)rA���N)�defaultrA���c�������������C���s8���|�j�dk r|���|||��x|D�]}|��|||��qW�dS�)zP We use a callable class to be able to change the ``__repr__``. N)�iterable_validator�member_validator)r���r ���r!���r����memberr"���r"���r#���r$���/��s���� z_DeepIterable.__call__c�������������C���s,���|�j�d�krdndj|�j�d�}dj||�jd�S�)N��z {iterable!r})�iterablezJ<deep_iterable validator for{iterable_identifier} iterables of {member!r}>)�iterable_identifierrN���)rL���r���rM���)r���rQ���r"���r"���r#���r%���9��s ����z_DeepIterable.__repr__) r&���r'���r(���r���r���rM���r���rL���r$���r%���r"���r"���r"���r#���rJ���(��s ��� rJ���c�������������C���s ���t�|�|�S�)a1�� A validator that performs deep validation of an iterable. :param member_validator: Validator 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 )rJ���)rM���rL���r"���r"���r#���r���H��s����c���������������@���sF���e�Zd�Zee��d�Zee��d�Zedee���d�Zdd��Z dd��Z dS�)�_DeepMapping)rA���N)rK���rA���c�������������C���sJ���|�j�dk r|���|||��x,|D�]$}|��|||��|��||||���qW�dS�)zP We use a callable class to be able to change the ``__repr__``. N)�mapping_validator� key_validator�value_validator)r���r ���r!���r����keyr"���r"���r#���r$���]��s ���� z_DeepMapping.__call__c�������������C���s���dj�|�j|�jd�S�)NzA<deep_mapping validator for objects mapping {key!r} to {value!r}>)rV���r���)r���rT���rU���)r���r"���r"���r#���r%���h��s����z_DeepMapping.__repr__)r&���r'���r(���r���r���rT���rU���r���rS���r$���r%���r"���r"���r"���r#���rR���W��s ���rR���c�������������C���s���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 )rR���)rT���rU���rS���r"���r"���r#���r���n��s���� )r���N)N)N)�__doc__� __future__r���r���r���r6����_maker���r���r���r ���� exceptionsr ����__all__�objectr���r���r*���r���r>���r���r@���r���rD���r ���rF���r���rJ���r���rR���r���r"���r"���r"���r#����<module>���sJ��� -