/usr/local/lib/python3.6/site-packages/attr/__pycache__
NameSizeModeActions
converters.cpython-36.pyc34730644editdlrm
exceptions.cpython-36.pyc31680644editdlrm
filters.cpython-36.pyc15840644editdlrm
setters.cpython-36.pyc14700644editdlrm
validators.cpython-36.pyc207030644editdlrm
_cmp.cpython-36.pyc36910644editdlrm
_compat.cpython-36.pyc40570644editdlrm
_config.cpython-36.pyc9500644editdlrm
_funcs.cpython-36.pyc102130644editdlrm
_make.cpython-36.pyc731880644editdlrm
_next_gen.cpython-36.pyc51430644editdlrm
_version_info.cpython-36.pyc22750644editdlrm
__init__.cpython-36.pyc21120644editdlrm
Edit: /usr/local/lib/python3.6/site-packages/attr/__pycache__/validators.cpython-36.pyc (20703B)
3 8%EgP@sdZddlZddlZddlmZddlmZmZddlm Z m Z m Z m Z ddl mZddlmZy ejZWn"ek reejd ZYnXd 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/dZ e d d!d!d"Gd0d1d1Z!d2dZ"e d d d!d"Gd3d4d4Z#d5dZ$e d d!d!d"Gd6d7d7Z%dQd8d Z&e d d!d!d"Gd9d:d:Z'dRd;d Z(e d d!d!d&GddZ*d?dZ+d@dZ,dAdZ-e d d!d!d&GdBdCdCZ.dDdZ/e d d!d!d&GdEdFdFZ0dGdZ1e d d!d!d"GdHdIdIZ2dJdKZ3e d d!d!d"GdLdMdMZ4de5e6fdNdOdZ7dS)Sz Commonly useful validators. N)contextmanager)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_optionalprovides 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)rr9/usr/local/lib/python3.6/site-packages/attr/validators.pyr0scCst 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 )rrrrr rBs c cs"tdz dVWdtdXdS)z Context manager that disables running validators within its context. .. warning:: This context manager is not thread-safe! .. versionadded:: 21.3.0 FNT)rrrrr rNs  FT)reprslotshashc@s"eZdZeZddZddZdS)_InstanceOfValidatorcCs4t||js0tdj|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}).)nametypeactualvalueN) isinstancer& TypeErrorformatr% __class__)selfinstattrr(rrr __call__ds z_InstanceOfValidator.__call__cCsdj|jdS)Nz))r&)r+r&)r-rrr __repr__vsz_InstanceOfValidator.__repr__N)__name__ __module__ __qualname__rr&r0r1rrrr r$`sr$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). :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&rrr r|s )r!frozenr"c@s(eZdZeZeZddZddZdS)_MatchesReValidatorcCs0|j|s,tdj|j|jj|d||j|dS)zP We use a callable class to be able to change the ``__repr__``. z9'{name}' must match regex {pattern!r} ({value!r} doesn't))r%patternr(N) match_func ValueErrorr+r%r7)r-r.r/r(rrr r0s z_MatchesReValidator.__call__cCsdj|jdS)Nz.)r7)r+r7)r-rrr r1sz_MatchesReValidator.__repr__N)r2r3r4rr7r8r0r1rrrr r6sr6cCstjdtjtjf}||kr@tdjdjtddt|Dt |t r\|rVt d|}n tj ||}|tjkrz|j}n|tjkr|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|jpdVqdS)NoneN)r2).0errr szmatches_re..zR'flags' can only be used with a string pattern; pass flags to re.compile() instead)re fullmatchsearchmatchr9r+joinsortedsetr)Patternr*compiler6)regexflagsfuncZ valid_funcsr7r8rrr rs&    c@s"eZdZeZddZddZdS)_ProvidesValidatorcCs0|jj|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)rKZ providedByr*r+r%)r-r.r/r(rrr r0s z_ProvidesValidator.__call__cCsdj|jdS)Nz0)rK)r+rK)r-rrr r1sz_ProvidesValidator.__repr__N)r2r3r4rrKr0r1rrrr rJsrJcCst|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 `_). :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. )rJ)rKrrr rsc@s"eZdZeZddZddZdS)_OptionalValidatorcCs|dkr dS|j|||dS)N) validator)r-r.r/r(rrr r0sz_OptionalValidator.__call__cCsdjt|jdS)Nz')what)r+r!rM)r-rrr r1 sz_OptionalValidator.__repr__N)r2r3r4rrMr0r1rrrr rLsrLcCst|trtt|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 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)listrLr)rMrrr rs  c@s"eZdZeZddZddZdS) _InValidatorcCsPy||jk}Wntk r&d}YnX|sLtdj|j|j|d||j|dS)NFz/'{name}' must be in {options!r} (got {value!r}))r%optionsr()rQr*r9r+r%)r-r.r/r(Z in_optionsrrr r0&s z_InValidator.__call__cCsdj|jdS)Nz()rQ)r+rQ)r-rrr r16sz_InValidator.__repr__N)r2r3r4rrQr0r1rrrr rP"srPcCst|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. )rP)rQrrr r<sc@seZdZddZddZdS)_IsCallableValidatorcCs,t|s(d}t|j|j||jd|ddS)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(messagerrr r0Ts z_IsCallableValidator.__call__cCsdS)Nzr)r-rrr r1dsz_IsCallableValidator.__repr__N)r2r3r4r0r1rrrr rRRsrRcCstS)ax 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 (`attrs.Attribute`) name, and the value it got. )rRrrrr rhs c@s:eZdZeedZedeedZddZddZ dS) _DeepIterable)rMN)defaultrMcCs8|jdk r|j|||x|D]}|j|||qWdS)zP We use a callable class to be able to change the ``__repr__``. N)iterable_validatormember_validator)r-r.r/r(memberrrr r0~s  z_DeepIterable.__call__cCs*|jdkrdn d|j}dj||jdS)Nr  zJ)iterable_identifierrZ)rXr+rY)r-r\rrr r1s  z_DeepIterable.__repr__) r2r3r4rrrYrrXr0r1rrrr rVws   rVcCs t|ttfrt|}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)rOtuplerrV)rYrXrrr r s c@sFeZdZeedZeedZedeedZddZ ddZ dS) _DeepMapping)rMN)rWrMcCsJ|jdk r|j|||x,|D]$}|j||||j||||qWdS)zP We use a callable class to be able to change the ``__repr__``. N)mapping_validator key_validatorvalue_validator)r-r.r/r(keyrrr r0s   z_DeepMapping.__call__cCsdj|j|jdS)NzA)rbr()r+r`ra)r-rrr r1sz_DeepMapping.__repr__) r2r3r4rrr`rarr_r0r1rrrr r^s    r^cCs 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`rar_rrr rs c@s.eZdZeZeZeZddZddZdS)_NumberValidatorcCs.|j||js*tdj|j|j|j|ddS)zP We use a callable class to be able to change the ``__repr__``. z&'{name}' must be {op} {bound}: {value})r%opboundr(N) compare_funcrer9r+r% compare_op)r-r.r/r(rrr r0sz_NumberValidator.__call__cCsdj|j|jdS)Nz)rdre)r+rgre)r-rrr r1sz_NumberValidator.__repr__N) r2r3r4rrergrfr0r1rrrr rcs rccCst|dtjS)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 <)rcoperatorr)valrrr rs cCst|dtjS)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<=)rcrir)rjrrr rs cCst|dtjS)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>=)rcrir)rjrrr rs cCst|dtjS)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 >)rcrir)rjrrr r s c@s"eZdZeZddZddZdS)_MaxLengthValidatorcCs.t||jkr*tdj|j|jt|ddS)zP We use a callable class to be able to change the ``__repr__``. z*Length of '{name}' must be <= {max}: {len})r%maxlenN)rn max_lengthr9r+r%)r-r.r/r(rrr r0sz_MaxLengthValidator.__call__cCsd|jdS)Nz {min}: {len})r%minrnN)rn min_lengthr9r+r%)r-r.r/r(rrr r0<sz_MinLengthValidator.__call__cCsd|jdS)Nz)r&)r+r&)r-rrr r1lsz_SubclassOfValidator.__repr__N)r2r3r4rr&r0r1rrrr rtWsrtcCst|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. )rt)r&rrr _subclass_ofrs rvc@sJeZdZeZeeddZeeee e e ddZ ddZ ddZd S) _NotValidatorzCnot_ validator child '{validator!r}' did not raise a captured error) converter)rYrX)rMcCsRy|j|||Wn|jk r(Yn&Xt|jj|j|jd||j||jdS)N)rM exc_types)rMryr9rSr+)r-r.r/r(rrr r0sz_NotValidator.__call__cCsdj|j|jdS)Nz;)rNry)r+rMry)r-rrr r1sz_NotValidator.__repr__N)r2r3r4rrMr rSr rv Exceptionrr]ryr0r1rrrr rws rw)rSryc Cs4y t|}Wntk r&|f}YnXt|||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 )r]r*rw)rMrSryrrr rs   )rN)N)N)8__doc__rir> contextlibr_configrr_makerrrr convertersr exceptionsr rEAttributeErrorr&rF__all__rrrr$rr6rrJrrLrrPrrRrrVr r^rrcrrrrrlrrqrrtrvrwr9r*rrrrr s|      0        *