L iSxdZddlZddlZddlmZddlmZddlmZmZddl m Z m Z m Z m Z ddlmZdd lmZgd Zd Zd Zed Ze dddGddZdZe dddGddZd=dZe dddGddZdZe dddGddZdZe dddGddZd Ze dddGd!d"Z d>d#Z!e dddGd$d%Z" d?d&Z#e dddGd'd(Z$d)Z%d*Z&d+Z'd,Z(e dddGd-d.Z)d/Z*e dddGd0d1Z+d2Z,e dddGd3d4Z-d5Z.e dddGd6d7Z/de0e1fd8d9Z2e dddGd:d;Z3d<Z4y)@z Commonly useful validators. N)contextmanager)Pattern)get_run_validatorsset_run_validators) _AndValidatorand_attribattrs)default_if_none)NotCallableError)r deep_iterable deep_mappingdisabledge get_disabledgtin_ instance_of is_callablelelt matches_remax_lenmin_lennot_optionalor_ set_disabledct| y)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)rs U/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/attr/validators.pyrr*s8|$ct 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"rr<s"# ##r#c#bKtd dtdy#tdwxYww)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"rrHs)u! 4 4 s / / ,/FT)reprslots unsafe_hashc&eZdZeZdZdZy)_InstanceOfValidatorc t||jsEd|jd|jd|d|jd }t |||j|y)P We use a callable class to be able to change the ``__repr__``. ' ' must be  (got z that is a ).N) isinstancetypename __class__ TypeErrorselfinstattrvaluemsgs r"__call__z_InstanceOfValidator.__call__^se%+dii[ 499-veYkRWRaRaQddfgC   ,r#c"d|jdS)Nz r3r8s r"__repr__z_InstanceOfValidator.__repr__k1$))a@@r#N__name__ __module__ __qualname__r r3r=rBr%r#r"r+r+Z 8D Ar#r+ct|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(c4eZdZeZeZdZdZy)_MatchesReValidatorc|j|sBd|jd|jjd|d}t|||j|y)r-r.z' must match regex z (z doesn't)N) match_funcr4pattern ValueErrorr7s r"r=z_MatchesReValidator.__call__s]u%dii[ 3DLL4H4H3K2eYV_`C   &r#c"d|jdS)Nz"zmatches_re..s!N(ajj3V3Ns zR'flags' can only be used with a string pattern; pass flags to re.compile() instead)re fullmatchsearchmatchformatjoinsortedsetrQr2rr6compilerM)regexflagsfunc valid_funcsr<rPrOs r"rrs*<<ryy"((;K ;)00 IINS=MNN   o%! fCC. **UE* rxx]]  ^^ && w 33r#c&eZdZeZdZdZy)_OptionalValidatorc0|y|j|||yN validatorr8r9r:r;s r"r=z_OptionalValidator.__call__s =  tT5)r#c"d|jdS)NzrjrAs r"rBz_OptionalValidator.__repr__s)$..);9EEr#N)rErFrGr rkr=rBr%r#r"rgrgsI* Fr#rgclt|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. )r2listtuplergrrjs r"rrs-)dE]+!- ":;; i ((r#c8eZdZeZedZdZdZy) _InValidatorF)hashc ||jv}|s8d|jd|jd|d}t |||j|y#t$rd}YHwxYw)NFr.z ' must be in r0))optionsr6r4_original_optionsrQ)r8r9r:r; in_optionsr<s r"r=z_InValidator.__call__sz $,,.Jdii[ d.D.D-GveYVWXC&&   J sA AAc"d|jdS)Nzr%rAs r"rBz_IsCallableValidator.__repr__6s(r#N)rErFrGr=rBr%r#r"r~r~$s  )r#r~ctS)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^eZdZeeZedeeZdZdZ y) _DeepIterablerjN)defaultrkcv|j|j||||D]}|j|||yr-Niterable_validatormember_validator)r8r9r:r;members r"r=z_DeepIterable.__call__QsC  " " .  # #D$ 6 6F  ! !$f 5 6r#cb|jdnd|j}d|d|jdS)N z*?T225Q 8 r#) rErFrGr rrrrr=rBr%r#r"rrJs0 6 76  r#rct|ttfrt|}t|ttfrt|}t ||S)a A validator that performs deep validation of an iterable. Args: member_validator: Validator(s) to apply to iterable members. iterable_validator: Validator(s) to apply to iterable itself (optional). Raises TypeError: if any sub-validators fail .. versionadded:: 19.1.0 .. versionchanged:: 25.4.0 *member_validator* and *iterable_validator* can now be a list or tuple of validators. )r2rorpr rrrs r"rrgsI&"T5M2!12$tUm4!#56 )+= >>r#ceZdZeeeZeeeZeeeZdZ dZ y) _DeepMappingrjc|j|j||||D]D}|j|j||||j/|j||||Fyr)mapping_validator key_validatorvalue_validator)r8r9r:r;keys r"r=z_DeepMapping.__call__sq  ! ! -  " "4u 5 =C!!-""4s3##/$$T4s<  =r#c<d|jd|jdS)Nz,P>P=SSWX\XlXlWoopqqr#N) rErFrGr rrrrrr=rBr%r#r"rrsAXkm%<=Mx '>?O+-)@A =rr#rc|| d}t|t|ttfrt |}t|ttfrt |}t|ttfrt |}t |||S)a A validator that performs deep validation of a dictionary. All validators are optional, but at least one of *key_validator* or *value_validator* must be provided. Args: key_validator: Validator(s) to apply to dictionary keys. value_validator: Validator(s) to apply to dictionary values. mapping_validator: Validator(s) to apply to top-level mapping attribute. .. versionadded:: 19.1.0 .. versionchanged:: 25.4.0 *key_validator* and *value_validator* are now optional, but at least one of them must be provided. .. versionchanged:: 25.4.0 *key_validator*, *value_validator*, and *mapping_validator* can now be a list or tuple of validators. Raises: TypeError: If any sub-validator fails on validation. ValueError: If neither *key_validator* nor *value_validator* is provided on instantiation. zAAt least one of key_validator or value_validator must be provided)rQr2rorpr r)rrrr<s r"rrsD!8 O o-$/m, /D%=10#dE]3 "34  8I JJr#cBeZdZeZeZeZdZdZy)_NumberValidatorc|j||js7d|jd|jd|jd|}t |y)r-r.r/r: N) compare_funcboundr4 compare_oprQr7s r"r=z_NumberValidator.__call__sR   3dii[ 4??*;1TZZL5'RCS/ !4r#c<d|jd|jdS)Nz=)rrrrs r"rrrr#c8t|dtjS)a  A validator that raises `ValueError` if the initializer is called with a number smaller or equal to *val*. The validator uses `operator.gt` to compare the values. Args: val: Exclusive lower bound for values .. versionadded:: 21.3.0 r?)rrrrs r"rr rr#c&eZdZeZdZdZy)_MaxLengthValidatorct||jkDr3d|jd|jdt|}t|y)r- Length of 'z ' must be <= rN)len max_lengthr4rQr7s r"r=z_MaxLengthValidator.__call__H u: ' {-7H3u:,WCS/ ! (r#c"d|jdS)Nz= rN)r min_lengthr4rQr7s r"r=z_MinLengthValidator.__call__9rr#c"d|jdS)Nz>*r#rcg}|D]0}|jt|tr |jn|g2tt |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 )extendr2rrrp)rvalsrs r"rrsH& D J Jq,$?ALLaSIJ d $$r#)rNri)NNN)5__doc__rrY contextlibrr_configrr_makerr r r convertersr exceptionsr __all__rrrr+rrMrrgrrrrr~rrrrrrrrrrrrrrrrrrQr6rrrr%r#r"rs %;55'( .%$ $!!"E40AA1A(&"E$d+FF,F*-4`E40 F F1 F)*E40JJ1J. /FED1))2)* " E40  1 8?4E40rr1r.AE/KdE$d+CC,C" 3 4 4 3E$d+ < <, < 'E$d+ < <, < 'E40AA1A(&"E40!]!]1!]H J +B!4HE40>>1>&%r#