var/opt/nydus/ops/attr/__pycache__/validators.cpython-38.pyc000064400000050167147205577540020114 0ustar00U afMN@sdZddlZddlZddlmZddlmZddlmZmZddl m Z m Z m Z m Z ddlmZdd lmZd d d d dddddddddddddddgZddZddZedd Ze d d!d!d"Gd#d$d$Zd%dZe d d!d!d&Gd'd(d(ZdPd)dZe d d!d!d"Gd*d+d+Zd,dZe d d!d!d"Gd-d.d.Zd/dZe d d d!d"Gd0d1d1Zd2dZe d d!d!d"Gd3d4d4Z dQd5d Z!e d d!d!d"Gd6d7d7Z"dRd8d Z#e d d!d!d&Gd9d:d:Z$d;dZ%ddZ(e d d!d!d&Gd?d@d@Z)dAdZ*e d d!d!d&GdBdCdCZ+dDdZ,e d d!d!d"GdEdFdFZ-dGdHZ.e d d!d!d"GdIdJdJZ/de0e1fdKdLdZ2e d d!d!d"GdMdNdNZ3dOdZ4dS)Sz Commonly useful validators. N)contextmanager)Pattern)get_run_validatorsset_run_validators) _AndValidatorand_attribattrs)default_if_none)NotCallableErrorr deep_iterable deep_mappingdisabledge get_disabledgtin_ instance_of is_callablelelt matches_remax_lenmin_lennot_optionalor_ 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 Nr)rr @/opt/nydus/tmp/pip-target-53d1vnqk/lib/python/attr/validators.pyr+scCst 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 ccs"tdz dVW5tdXdS)z Context manager that disables running validators within its context. .. warning:: This context manager is not thread-safe! .. versionadded:: 21.3.0 FTNrr r r r!rIs  FT)reprslotsZ unsafe_hashc@s"eZdZeZddZddZdS)_InstanceOfValidatorc CsDt||js@d|jd|jd|d|jd }t|||j|dS)P We use a callable class to be able to change the ``__repr__``. ' ' must be  (got z that is a ).N) isinstancetypename __class__ TypeErrorselfinstattrvaluemsgr r r!__call___s $z_InstanceOfValidator.__call__cCsd|jdS)Nz r+r0r r r!__repr__lsz_InstanceOfValidator.__repr__N__name__ __module__ __qualname__r r+r5r9r 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 `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!rps)r"frozenr#c@s(eZdZeZeZddZddZdS)_MatchesReValidatorcCs<||s8d|jd|jjd|d}t|||j|dS)r%r&z' must match regex z (z doesn't)N) match_funcr,pattern ValueErrorr/r r r!r5s z_MatchesReValidator.__call__cCsd|jdS)Nz"szmatches_re..zR'flags' can only be used with a string pattern; pass flags to re.compile() instead)re fullmatchsearchmatchformatjoinsortedsetrBr*rr.compiler?)regexflagsfuncZ valid_funcsr4rAr@r r r!rs(    c@s"eZdZeZddZddZdS)_OptionalValidatorcCs|dkr dS||||dS)N validatorr0r1r2r3r r r!r5sz_OptionalValidator.__call__cCsd|jdS)NzrTr8r r r!r9sz_OptionalValidator.__repr__N)r;r<r=r rUr5r9r r r r!rSsrScCs"t|ttfrtt|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*listtuplerSrrTr r r!rs c@s,eZdZeZeddZddZddZdS) _InValidatorF)hashcCs\z||jk}Wntk r&d}YnX|sXd|jd|jd|d}t|||j|dS)NFr&z ' must be in r())optionsr.r,_original_optionsrB)r0r1r2r3Z in_optionsr4r r r!r5s z_InValidator.__call__cCsd|jdS)Nzr r8r r r!r97sz_IsCallableValidator.__repr__N)r;r<r=r5r9r r r r!r_%sr_cCstS)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 c@s:eZdZeedZedeedZddZddZ dS) _DeepIterablerTNdefaultrUcCs4|jdk r|||||D]}||||qdSr%Niterable_validatormember_validator)r0r1r2r3memberr r r!r5Rs z_DeepIterable.__call__cCs.|jdkrdn d|j}d|d|jdS)N z=)rsryrrzr r r!rs cCst|dtjS)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)rsryrrzr r r!rs c@s"eZdZeZddZddZdS)_MaxLengthValidatorcCs8t||jkr4d|jd|jdt|}t|dS)r% Length of 'z ' must be <= rtN)len max_lengthr,rBr/r r r!r5sz_MaxLengthValidator.__call__cCsd|jdS)Nz= rtN)r~ min_lengthr,rBr/r r r!r5sz_MinLengthValidator.__call__cCsd|jdS)Nzsz_SubclassOfValidator.__repr__Nr:r r r r!r-s rcCst|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. )rr7r r r! _subclass_ofBsrc@sJeZdZeZeeddZeeee e e ddZ ddZ ddZd S) _NotValidatorzCnot_ validator child '{validator!r}' did not raise a captured error) converterrmrTcCsRz||||Wn|jk r(Yn&Xt|jj|j|jd||j||jdS)NrU exc_types)rUrrBr4rKrVr r r!r5csz_NotValidator.__call__cCsd|jd|jdS)Nzs         0   #          $$