kfPhdZddlZddlZddlmZddlmZddlmZmZddl 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#Z!e 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 dddGd0d1Z+d2Z,e dddGd3d4Z-d5Z.e dddGd6d7Z/d8Z0e dddGd9d:Z1de2e3fd;d<Z4dS)?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_optionalprovides set_disabledc&t| 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 Nr)rs o/builddir/build/BUILD/imunify360-venv-2.3.5/opt/imunify360/venv/lib/python3.11/site-packages/attr/validators.pyrr+s8|$$$$$c t 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 )rr#r"rr=s"## ##r#c#xKtd dVtddS#tdwxYw)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"rrIsMu! 4     4    s(9FT)reprslotshashc.eZdZeZdZdZdS)_InstanceOfValidatorct||js=td|j|j|j|||j|dS)P 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__selfinstattrr1s r"__call__z_InstanceOfValidator.__call___sl%++ %v ? &         r#c8d|jS)Nz)r/r4r/r7s r"__repr__z_InstanceOfValidator.__repr__q%:AAB   r#N__name__ __module__ __qualname__r r/r:r?r%r#r"r+r+[s= 688D$     r#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). :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<s r"rrw  % %%r#)r'frozenr(cBeZdZeZeZdZdZdS)_MatchesReValidatorc||s)rK)r4rKr>s r"r?z_MatchesReValidator.__repr__s%?FFLG   r#N)rBrCrDr rKrLr:r?r%r#r"rIrIsHfhhGJ        r#rIc tjdtjtjf}||vrYt ddtdt|Dt|tr|rtd|}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*. :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, c3,K|]}|r|jpdVdS)NoneN)rB).0es r" zmatches_re..s?78(aj2Fr#zR'flags' can only be used with a string pattern; pass flags to re.compile() instead)re fullmatchsearchmatchrMr4joinsortedsetr2rr3compilerI)regexflagsfunc valid_funcsrKrLs r"rrs <ry"(;K ; ' . . )rd)r4rdr>s r"r?z_ProvidesValidator.__repr__s%AHHnI   r#N)rBrCrDr rdr:r?r%r#r"rbrbs=I        r#rbcbddl}|dtdt|S)aE 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. .. deprecated:: 23.1.0 rNzZattrs's zope-interface support is deprecated and will be removed in, or after, April 2024.) stacklevel)warningswarnDeprecationWarningrb)rdrjs r"rrsC OOO MM   i ( ((r#c.eZdZeZdZdZdS)_OptionalValidatorc<|dS||||dSN validatorr6s r"r:z_OptionalValidator.__call__ s( = F tT5)))))r#cRdt|jS)Nz')what)r4r'rrr>s r"r?z_OptionalValidator.__repr__s-8??dn%%@   r#N)rBrCrDr rrr:r?r%r#r"rnrns=I***      r#rnct|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. :param Callable | tuple[Callable] | list[Callable] validator: 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. )r2listtuplernrrqs r"rrs>)dE]++<!- ":":;;; i ( ((r#c.eZdZeZdZdZdS) _InValidatorc ||jv}n#t$rd}YnwxYw|s7td|j|j|||j|dS)NFz/'{name}' must be in {options!r} (got {value!r}))r.optionsr1)r{r3rMr4r.)r7r8r9r1 in_optionss r"r:z_InValidator.__call__,s $,.JJ   JJJ  AHHDLI     s c8d|jS)Nz(r{)r4r{r>s r"r?z_InValidator.__repr__<s%9@@LA   r#N)rBrCrDr r{r:r?r%r#r"ryry(s=fhhG      r#ryc 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 `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. )ryr~s r"rrBs&   r#ceZdZdZdZdS)_IsCallableValidatorct|s3d}t||j||j|dS)r-z?'{name}' must be callable (got {value!r} that is a {actual!r}).)r.r1r0)msgr1N)callabler r4r.r5)r7r8r9r1messages r"r:z_IsCallableValidator.__call__Zse 8 #NN%#    r#cdS)Nzr%r>s r"r?z_IsCallableValidator.__repr__js((r#N)rBrCrDr:r?r%r#r"rrXs2 )))))r#rctS)ax 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. )rr%r#r"rrns ! !!r#c~eZdZeeZedeeZdZdZ dS) _DeepIterablerqNdefaultrrcz|j|||||D]}||||dSr-N)iterable_validatormember_validator)r7r8r9r1members r"r:z_DeepIterable.__call__sY  " .  # #D$ 6 6 6 6 6F  ! !$f 5 5 5 5 6 6r#c`|jdn d|j}d||jS)N zJ)iterable_identifierr)rr4r)r7rs r"r?z_DeepIterable.__repr__sN&. B0T,00   ( & 3(    r#) rBrCrDr rrrrr:r?r%r#r"rr}swv 666 7 7666      r#rclt|ttfr t|}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 )r2rvrwr rrrs r"rrs9"T5M223!12 )+= > >>r#ceZdZeeZeeZedeeZdZ dZ dS) _DeepMappingrqNrc|j|||||D]6}|||||||||7dSr)mapping_validator key_validatorvalue_validator)r7r8r9r1keys r"r:z_DeepMapping.__call__su  ! -  " "4u 5 5 5 9 9C   tT3 / / /  tU3Z 8 8 8 8 9 9r#cDd|j|jS)NzA)rr1)r4rrr>s r"r?z_DeepMapping.__repr__s" O &T't/C& D D Er#) rBrCrDr rrrrrr:r?r%r#r"rrsF[[]]333Mf{{}}555Otxx 7N7NOOO 9 9 9EEEEEr#rc$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)rrrs r"rrs  8I J JJr#cVeZdZeZeZeZdZdZdS)_NumberValidatorc|||js5td|j|j|j|dS)r-z&'{name}' must be {op} {bound}: {value})r.opboundr1N) compare_funcrrMr4r. compare_opr6s r"r:z_NumberValidator.__call__se   33 8??* @   r#cDd|j|jS)Nz)rr)r4rrr>s r"r?z_NumberValidator.__repr__s(/66dj7   r#N) rBrCrDr rrrr:r?r%r#r"rrsS FHHEJ688L        r#rc8t|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 <)roperatorrvals r"rr Chk 2 22r#c8t|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<=)rrrrs r"rr Cx{ 3 33r#c8t|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>=)rrrrs r"rrrr#c8t|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 >)rrrrs r"rrrr#c.eZdZeZdZdZdS)_MaxLengthValidatorc t||jkrs r"r?z_MaxLengthValidator.__repr__.;;;;;r#N)rBrCrDr rr:r?r%r#r"rr=J   <<<< {min}: {len})r.minrN)r min_lengthrMr4r.r6s r"r:z_MinLengthValidator.__call__Brr#cd|jdS)Nzs r"r?z_MinLengthValidator.__repr__Mrr#N)rBrCrDr rr:r?r%r#r"rr>rr#rc t|S)z A validator that raises `ValueError` if the initializer is called with a string or iterable that is shorter than *length*. :param int length: Minimum length of the string or iterable .. versionadded:: 22.1.0 )rrs r"rrQrr#c.eZdZeZdZdZdS)_SubclassOfValidatorct||js7td|j|j|||j|dS)r-z8'{name}' must be a subclass of {type!r} (got {value!r}).)r.r/r1N) issubclassr/r3r4r.r6s r"r:z_SubclassOfValidator.__call__asg%++ ##)6$*$$       r#c8d|jS)Nz)r<r=r>s r"r?z_SubclassOfValidator.__repr__rr@r#NrAr%r#r"rr]s= 688D"     r#rc 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). :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. )rr<s r" _subclass_ofrxrFr#ceZdZeZeedZeeee e e Z dZ dZdS) _NotValidatorzCnot_ validator child '{validator!r}' did not raise a captured error) converterrrqc ||||t|j|j|j||j||j#|j$rYdSwxYw)N)rr exc_types)rrrMrr4rr6s r"r:z_NotValidator.__call__s  NN4u - - -"n"n    ~    DD sA A('A(cDd|j|jS)Nz;)rtr)r4rrrr>s r"r?z_NotValidator.__repr__s( L &n    r#N)rBrCrDr rrr rrr Exceptionrrwrr:r?r%r#r"rrsI &!/ -     C -)\)44*{511   I"     r#r)rrcl 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_(...))``. :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 )rwr3r)rrrrs r"rrsN4!)$$ !!!L ! C 3 33s  "")rNrp)5__doc__rrU contextlibrr_configrr_makerr r r convertersr exceptionsr __all__rrrr+rrIrrbrrnrryrrrrrrrrrrrrrrrrrrrrMr3rr%r#r"rs  %%%%%%;;;;;;;;555555555555''''''((((((   .%%%$ $ $ $!!!"ED)))       *) 6 & & & E$d+++       ,+ 2-4-4-4-4`ED)))       *) 0)))6ED)))        *)  )))&ED)))       *) 2!!!,ET***)))))))+*)* " " "ED)))       *) >????"ED)))EEEEEEE*)E, K K K K E$d+++       ,+ 2 3 3 3 4 4 4 4 4 4 3 3 3E$d+++<<<<<<<,+<$ ' ' 'E$d+++<<<<<<<,+<$ ' ' 'ED)))       *) 4 & & & ED)))& & & & & & & *)& R J +B4444444r#