U nfP9 @sUddlZddlmZddlmZmZmZddlmZddl m Z ddl m Z m Z mZmZmZmZmZmZmZmZmZmZddlmZddlmZdd lmZmZe rdd lmZGd d d Z e r4dd l!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(eee(e ee)e fe&ee$ge fZ*ee*Z+ee)ee fZ,e-Z.ee)e/d<dZ0dZ1ddddddde)e2e2e2e2ee2e2eegdfdddZ3eeddddZ4edddde2e2e2eegdfdd dZ4dFddddeee2e2e2edeegdffd!d"dZ4ee2dd#d$d%Z5Gd&d'd'Z6ee)e fee)ee fd(d)d*Z7ee)e feeeeee2effd(d+d,Z8d-d-d-d.d/d0Z9ed1d2d3d4Z:eed5d6d7d8Z;d9d:d;hZd?Z=eddBee)dfdCdDdEZ?dS)GN)ChainMap)partial partialmethodwraps)chain) FunctionType) TYPE_CHECKINGAnyCallableDictIterableListOptionalSetTupleTypeUnionoverload) ConfigError) AnyCallable)ROOT_KEY in_ipython)AnyClassMethodc@s*eZdZdZdeeeeeedddZdS) Validatorfuncpre each_itemalways check_fieldsskip_on_failureFcCs(||_||_||_||_||_||_dSNr)selfrrrrrr r#J/opt/hc_python/lib/python3.8/site-packages/pydantic/v1/class_validators.py__init__s zValidator.__init__N)FFFFF)__name__ __module__ __qualname__ __slots__rboolr%r#r#r#r$rsr) Signature) BaseConfig) ModelField) ModelOrDc_FUNCSZ__validator_config__Z__root_validator_config__FT)rrrrwhole allow_reuser)fieldsrrrrr0r1returncsstdn2tdtr&tdntddDs@td|dk rjtdtd ksdtd | td d fd d }|S)a Decorate methods on the class indicating that they should be used to validate fields :param fields: which field(s) the method should be called on :param pre: whether or not this validator should be called before the standard validators (else after) :param each_item: for complex objects (sets, lists etc.) whether to validate individual elements rather than the whole object :param always: whether this method and other validators should be called even if the value is missing :param check_fields: whether to check that the fields actually exist on the model :param allow_reuse: whether to track and raise an error if another validator refers to the decorated function z"validator with no fields specifiedrz}validators should be used with fields and keyword arguments, not bare. E.g. usage should be `@validator('', ...)`css|]}t|tVqdSr!) isinstancestr).0fieldr#r#r$ Nszvalidator..zvalidator fields should be passed as separate string args. E.g. usage should be `@validator('', '', ...)`NzdThe "whole" keyword argument is deprecated, use "each_item" (inverse meaning, default False) insteadFz0"each_item" and "whole" conflict, remove "whole"rfr3c s.t|}t|tt|jdf|S)N)rrrrr)_prepare_validatorsetattrVALIDATOR_CONFIG_KEYr__func__r:f_clsr1rrrr2rr#r$dec\s zvalidator..dec) rr4rallwarningswarnDeprecationWarningAssertionErrorr)rrrrr0r1r2rBr#rAr$ validator4s&  rH)_funcr3cCsdSr!r#)rIr#r#r$root_validatorksrJrr1r )rr1r r3cCsdSr!r#rKr#r#r$rJps)rIrr1r r3csF|r*t|}t|tt|jd|Stddfdd }|S)z Decorate methods on a model indicating that they should be used to validate (and perhaps modify) data either before or after standard model parsing/validation is performed. rrr rr9cs&t|}t|tt|jd|S)NrL)r;r<ROOT_VALIDATOR_CONFIG_KEYrr>r?r1rr r#r$rBs zroot_validator..dec)r;r<rMrr>r)rIrr1r r@rBr#rNr$rJws )functionr1r3cCstt|tr|nt|}tsp|spt|jdddt|jddt|jd}|tkrftd|dt||S) z Avoid validators with duplicated names since without this, validators can be overwritten silently which generally isn't the intended behaviour, don't run in ipython (see #312) or if allow_reuse is False. r'z.r(zzduplicate validator function "z."; if this is intended, set `allow_reuse=True`) r4 classmethodrgetattrr>idr/radd)rOr1r@refr#r#r$r;s   r;c@sFeZdZdddddZeeeeefdddZdd d d Z dS) ValidatorGroupValidatorListDictN) validatorsr3cCs||_dh|_dS)N*)rYused_validators)r"rYr#r#r$r%szValidatorGroup.__init__)namer3cCsN|j||j|g}|tkr4||jdg7}|rFdd|DSdSdS)NrZcSs*i|]"}t|jddt|jd|qS)r&sz1ValidatorGroup.get_validators..)r[rUrYgetr)r"r\rYr#r#r$get_validatorss zValidatorGroup.get_validators)r3csJttfddjjD}|rFd|}td|ddS)Nc3s"|]}ddj|DVqdS)css0|](}|jrt|jddt|jdVqdS)r&r]rQN)rrSrrTr^r#r#r$r8sz..N)rYr6r:r"r#r$r8sz2ValidatorGroup.check_for_unused..z, z*Validators defined with incorrect fields: zO (use check_fields=False if you're inheriting from the model and intended this))setr from_iterablerYkeysr[joinr)r"Zunused_validatorsfnr#rdr$check_for_unuseds   zValidatorGroup.check_for_unused) r&r'r(r%r5rr rrbrjr#r#r#r$rWs rW) namespacer3cCs^i}|D]L\}}t|td}|r |\}}|D]&}||krL|||q0|g||<q0q |Sr!)itemsrSr=append)rkrYvar_namevaluevalidator_configr2r_r7r#r#r$extract_validatorss rqc Csddlm}g}g}|D]\}}t|td}|r||j}t|j}|ddkrnt d|d|dt |dkrt d|d|d|j r| |jq| |j |jfq||fS) Nr signaturer"z%Invalid signature for root validator : zC, "self" not permitted as first argument, should be: (cls, values).z, should be: (cls, values).)inspectrsrlrSrMrlist parametersrgrlenrrmr ) rkrsZpre_validatorsZpost_validatorsr\rorpsigargsr#r#r$extract_root_validatorss$     r|rX)base_validatorsrYr3cCs6|D](\}}||kr g||<|||7<q|Sr!)rl)r}rYr7Zfield_validatorsr#r#r$inherit_validatorss r~ValidatorCallable)rHr3csddlm}tttfs2|}t|j}n(|j}fdd|jjD}| d}|dkrt dd|dn@|d krt t |t |d d St t|t |Sd S) a Make a generic function which calls a validator with the right arguments. Unfortunately other approaches (eg. return a partial of a function that builds the arguments) is slow, hence this laborious way of doing things. It's done like this so validators don't all need **kwargs in their signature, eg. any combination of the arguments "values", "fields" and/or "config" are permitted. rrrcs$g|]}|jjBkr|qSr#)r{keywordsrg)r6krHr#r$ sz*make_generic_validator..r" Invalid signature for validator rtz, "self" not permitted as first argument, should be: (cls, value, values, config, field), "values", "config" and "field" are all optional.clsN)rvrsr4rrrwrxrgrpoprr_generic_validator_clsre_generic_validator_basic)rHrsrzr{Z first_argr#rr$make_generic_validators     rValidatorsList)v_funcsr3cCsdd|DS)NcSsg|]}|rt|qSr#)rrcr#r#r$rsz#prep_validators..r#)rr#r#r$prep_validatorssrvaluesr7configr+)rHrzr{r3csd}d|krd}|dh8}|ts:tdd|d|rJfddS|tkr`fd dS|d hkrvfd dS|d hkrfd dS|dhkrfddS|d d hkrfddS|d dhkr҇fddS|d dhkrfddSfddSdS)NFkwargsTrrtzb, should be: (cls, value, values, config, field), "values", "config" and "field" are all optional.cs|||||dSN)rr7rr#rr_rr7rrr#r$.z(_generic_validator_cls..cs ||Sr!r#rrr#r$r0rrcs|||dSN)rr#rrr#r$r2rr7cs|||dSN)r7r#rrr#r$r4rrcs|||dSN)rr#rrr#r$r6rcs||||dSN)rr7r#rrr#r$r8rcs||||dSN)rrr#rrr#r$r:rcs||||dSN)r7rr#rrr#r$r<rcs|||||dSrr#rrr#r$r?rissubset all_kwargsrrerHrzr{Z has_kwargsr#rr$r s2                 rcsd}d|krd}|dh8}|ts:tdd|d|rJfddS|tkr`fd dS|d hkrvfd dS|d hkrfd dS|dhkrfddS|d d hkrfddS|d dhkr҇fddS|d dhkrfddSfddSdS)NFrTrrtz], should be: (value, values, config, field), "values", "config" and "field" are all optional.cs||||dSrr#rrr#r$rOrz*_generic_validator_basic..cs|Sr!r#rrr#r$rQrrcs ||dSrr#rrr#r$rSrr7cs ||dSrr#rrr#r$rUrrcs ||dSrr#rrr#r$rWrcs|||dSrr#rrr#r$rYrcs|||dSrr#rrr#r$r[rcs|||dSrr#rrr#r$r]rcs||||dSrr#rrr#r$r`rrrr#rr$rBs2                 rr.)type_r3cCs&tdd|jD}dd|DS)NcSsg|] }|jqSr#)__dict__)r6rr#r#r$rdsz)gather_all_validators..cSs*i|]"\}}t|ts t|tr||qSr#)hasattrr=rM)r6rr_r#r#r$r`es  z)gather_all_validators..)r__mro__rl)rZall_attributesr#r#r$gather_all_validatorscsr)N)@rD collectionsr functoolsrrr itertoolsrtypesrtypingrr r r r r rrrrrrZpydantic.v1.errorsrZpydantic.v1.typingrZpydantic.v1.utilsrrrrrvr+Zpydantic.v1.configr,Zpydantic.v1.fieldsr-Zpydantic.v1.typesr.r5rrrXrer/__annotations__r=rMr*rHrJr;rWrqr|r~rrrrrrr#r#r#r$s   8       & 7  "$0' "!