g^UdZddlmZddlZddlZddlmZddlm Z ddl m Z m Z m Z mZmZmZmZddlmZddlmZddlmZmZmZd d lmZd d lmZmZmZm Z d d l!mZd d l"m#Z#ejHd krddlm%Z%nddl m%Z%ejLZ'ejPdFddie jRGddZ*ejPdFddie jRGddZ+ejPdFddie jRGddZ,ejPdFddie jRGddZ-e r~Gdde%Z.Gdde%Z/Gdde%Z0ee/ejbe.ejdfZ3ee0ejhfZ5ee6e e e fe7e e fee fZ8de9d <ed!e3e8Z:ed"e5e8Z;ed#d#d$ dGd%Zed-d.Z?Gd/d0eje%e?ZAGd1d2e%e>ZBGd3d4e%e>ZCGd5d6e%ZDGd7d8e%ZEGd9d:e%ZFGd;dge>fZH e e>ejge>fZJ eeCe>eBe>fZKeeFeGeDeEfZLeeJe>eHe>fZMe dJd=ZNe dKd>ZNe dLd?ZN dMd@ZNedAZOe reeOd#fZPn)ejPdFie jRGdBdCZPe reeOd#fZQyejPdFie jRGdDdEZQy)NzBThis module contains related classes and functions for validation.) annotationsN) partialmethod) FunctionType) TYPE_CHECKINGAnyCallableTypeVarUnioncastoverload) core_schema) AnnotatedLiteral TypeAlias)GetCoreSchemaHandler)_core_metadata _decorators _generics_internal_dataclass)PydanticUserError) )ProtocolfrozenTc$eZdZUdZded<ddZy)AfterValidatora8Usage docs: https://docs.pydantic.dev/2.8/concepts/validators/#annotated-validators A metadata class that indicates that a validation should be applied **after** the inner validation logic. Attributes: func: The validator function. Example: ```py from typing_extensions import Annotated from pydantic import AfterValidator, BaseModel, ValidationError MyInt = Annotated[int, AfterValidator(lambda v: v + 1)] class Model(BaseModel): a: MyInt print(Model(a=1).a) #> 2 try: Model(a='a') except ValidationError as e: print(e.json(indent=2)) ''' [ { "type": "int_parsing", "loc": [ "a" ], "msg": "Input should be a valid integer, unable to parse string as an integer", "input": "a", "url": "https://errors.pydantic.dev/2/v/int_parsing" } ] ''' ``` Kcore_schema.NoInfoValidatorFunction | core_schema.WithInfoValidatorFunctionfunccD||}t|jd}|rFttj|j}tj |||j Sttj|j}tj||S)Nafterschema field_namer#) _inspect_validatorrr r WithInfoValidatorFunction"with_info_after_validator_functionr$NoInfoValidatorFunction no_info_after_validator_functionself source_typehandlerr#info_argrs M/opt/hc_python/lib/python3.12/site-packages/pydantic/functional_validators.py__get_pydantic_core_schema__z+AfterValidator.__get_pydantic_core_schema__Isz%%dii9  ==tyyIDAA$vbibtbtu u ;;TYYGD??VT TNr-rr._GetCoreSchemaHandlerreturncore_schema.CoreSchema__name__ __module__ __qualname____doc____annotations__r1r2r0rrs'R VUUr2rc$eZdZUdZded<ddZy)BeforeValidatoraUsage docs: https://docs.pydantic.dev/2.8/concepts/validators/#annotated-validators A metadata class that indicates that a validation should be applied **before** the inner validation logic. Attributes: func: The validator function. Example: ```py from typing_extensions import Annotated from pydantic import BaseModel, BeforeValidator MyInt = Annotated[int, BeforeValidator(lambda v: v + 1)] class Model(BaseModel): a: MyInt print(Model(a=1).a) #> 2 try: Model(a='a') except TypeError as e: print(e) #> can only concatenate str (not "int") to str ``` rrcD||}t|jd}|rFttj|j}tj |||j Sttj|j}tj||S)Nbeforer"r%) r&rr r r'#with_info_before_validator_functionr$r)!no_info_before_validator_functionr+s r0r1z,BeforeValidator.__get_pydantic_core_schema__us{%%dii:  ==tyyIDBB4PVcjcucuv v ;;TYYGD@@fU Ur2Nr3r7r=r2r0r?r?Ts: VUVr2r?c$eZdZUdZded<ddZy)PlainValidatora;Usage docs: https://docs.pydantic.dev/2.8/concepts/validators/#annotated-validators A metadata class that indicates that a validation should be applied **instead** of the inner validation logic. Attributes: func: The validator function. Example: ```py from typing_extensions import Annotated from pydantic import BaseModel, PlainValidator MyInt = Annotated[int, PlainValidator(lambda v: int(v) + 1)] class Model(BaseModel): a: MyInt print(Model(a='1').a) #> 2 ``` rrcddlm} ||}tjd|}t |j d}|rFt tj|j }tj||j|St tj|j }tj||S#|$rd}YwxYw)NrPydanticSchemaGenerationErrorc||SNr=vhs r0z=PlainValidator.__get_pydantic_core_schema__..s bcdebfr2functionr#plain)r$ serialization)rR) pydanticrHr #wrap_serializer_function_ser_schemar&rr r'"with_info_plain_validator_functionr$r) no_info_plain_validator_function)r,r-r.rHr#rRr/rs r0r1z+PlainValidator.__get_pydantic_core_schema__s ; ![)F'KKUfouvM&dii9  ==tyyIDAA!3!3=  ;;TYYGD??Tab b- ! M !s CC  C Nr3r7r=r2r0rErEs. VUcr2rEc$eZdZUdZded<ddZy) WrapValidatoraUsage docs: https://docs.pydantic.dev/2.8/concepts/validators/#annotated-validators A metadata class that indicates that a validation should be applied **around** the inner validation logic. Attributes: func: The validator function. ```py from datetime import datetime from typing_extensions import Annotated from pydantic import BaseModel, ValidationError, WrapValidator def validate_timestamp(v, handler): if v == 'now': # we don't want to bother with further validation, just return the new value return datetime.now() try: return handler(v) except ValidationError: # validation failed, in this case we want to return a default value return datetime(2000, 1, 1) MyTimestamp = Annotated[datetime, WrapValidator(validate_timestamp)] class Model(BaseModel): a: MyTimestamp print(Model(a='now').a) #> 2032-01-02 03:04:05.000006 print(Model(a='invalid').a) #> 2000-01-01 00:00:00 ``` zScore_schema.NoInfoWrapValidatorFunction | core_schema.WithInfoWrapValidatorFunctionrcD||}t|jd}|rFttj|j}tj |||j Sttj|j}tj||S)Nwrapr"r%) r&rr r WithInfoWrapValidatorFunction!with_info_wrap_validator_functionr$NoInfoWrapValidatorFunctionno_info_wrap_validator_functionr+s r0r1z*WrapValidator.__get_pydantic_core_schema__sz%%dii8  AA499MD@@fahasast t ??KD>>tFS Sr2Nr3r7r=r2r0rXrXs"H ^]Tr2rXceZdZddZy)_OnlyValueValidatorClsMethodcyrJr=r,clsvalues r0__call__z%_OnlyValueValidatorClsMethod.__call__sCr2Nrcrrdrr5rr8r9r:rer=r2r0r`r`s?r2r`ceZdZddZy)_V2ValidatorClsMethodcyrJr=r,rcrdinfos r0rez_V2ValidatorClsMethod.__call__s_br2Nrcrrdrrl_core_schema.ValidationInfor5rrgr=r2r0ririsbr2ric(eZdZ ddZy)_V2WrapValidatorClsMethodcyrJr=r,rcrdr.rls r0rez"_V2WrapValidatorClsMethod.__call__sr2N) rcrrdrr.z)_core_schema.ValidatorFunctionWrapHandlerrlrnr5rrgr=r2r0rprps7   ?   .   r2rpr_PartialClsOrStaticMethod"_V2BeforeAfterOrPlainValidatorType_V2WrapValidatorType.)mode check_fieldscyrJr=fieldrvrwfieldss r0field_validatorr|s Z]r2)rwcyrJr=rys r0r|r|s>Ar2)rAr!rZrQFieldValidatorModesr!ct|tr tdd|gtdDs tdd dfd }|S) a:Usage docs: https://docs.pydantic.dev/2.8/concepts/validators/#field-validators Decorate methods on the class indicating that they should be used to validate fields. Example usage: ```py from typing import Any from pydantic import ( BaseModel, ValidationError, field_validator, ) class Model(BaseModel): a: str @field_validator('a') @classmethod def ensure_foobar(cls, v: Any): if 'foobar' not in v: raise ValueError('"foobar" not found in a') return v print(repr(Model(a='this is foobar good'))) #> Model(a='this is foobar good') try: Model(a='snap') except ValidationError as exc_info: print(exc_info) ''' 1 validation error for Model a Value error, "foobar" not found in a [type=value_error, input_value='snap', input_type=str] ''' ``` For more in depth examples, see [Field Validators](../concepts/validators.md#field-validators). Args: field: The first field the `field_validator` should be called on; this is separate from `fields` to ensure an error is raised if you don't pass at least one. *fields: Additional field(s) the `field_validator` should be called on. mode: Specifies whether to validate the fields before or after validation. check_fields: Whether to check that the fields actually exist on the model. Returns: A decorator that can be used to decorate a function to be used as a field_validator. Raises: PydanticUserError: - If `@field_validator` is used bare (with no fields). - If the args passed to `@field_validator` as fields are not strings. - If `@field_validator` applied to instance methods. z`@field_validator` should be used with fields and keyword arguments, not bare. E.g. usage should be `@validator('', ...)`zvalidator-no-fieldscodec3<K|]}t|tywrJ) isinstancestr).0rzs r0 z"field_validator..ls:6%z%%6sz`@field_validator` fields should be passed as separate string args. E.g. usage should be `@validator('', '', ...)`zvalidator-invalid-fieldsctj|r tddtj|}tj}tj ||S)Nz8`@field_validator` cannot be applied to instance methodszvalidator-instance-methodr)r{rvrw)ris_instance_method_from_sigr%ensure_classmethod_based_on_signatureFieldValidatorDecoratorInfoPydanticDescriptorProxy)fdec_inforwr{rvs r0deczfield_validator..decss`  2 21 5#JQl   = =a @::&tbno221h??r2)rzHCallable[..., Any] | staticmethod[Any, Any] | classmethod[Any, Any, Any]r5(_decorators.PydanticDescriptorProxy[Any])rrrall)rzrvrwr{rs ``` r0r|r|&sv~%& E&  ^V^F :6: : Y+  @ S @ 1 @ Jr2 _ModelType _ModelTypeCo) covariantc&eZdZdZ d ddZy)ModelWrapValidatorHandlerz[@model_validator decorated function handler argument type. This is used when `mode='wrap'`.NcyrJr=)r,rdouter_locations r0rez"ModelWrapValidatorHandler.__call__s r2rJ)rdrrzstr | int | Noner5rr8r9r:r;rer=r2r0rrs+e ,0  )   r2rc(eZdZdZ ddZy)ModelWrapValidatorWithoutInfozA @model_validator decorated function signature. This is used when `mode='wrap'` and the function does not have info argument. cyrJr=)r,rcrdr.s r0rez&ModelWrapValidatorWithoutInfo.__call__sr2N)rctype[_ModelType]rdrr.%ModelWrapValidatorHandler[_ModelType]r5rrr=r2r0rrs2     7   r2rc,eZdZdZ ddZy)ModelWrapValidatorzQA @model_validator decorated function signature. This is used when `mode='wrap'`.cyrJr=rrs r0rezModelWrapValidator.__call__sr2N) rcrrdrr.rrlrnr5rrr=r2r0rrs:[     7 *   r2rc eZdZdZ ddZy)#FreeModelBeforeValidatorWithoutInfoA @model_validator decorated function signature. This is used when `mode='before'` and the function does not have info argument. cyrJr=)r,rds r0rez,FreeModelBeforeValidatorWithoutInfo.__call__sr2N)rdrr5rrr=r2r0rrs    r2rc$eZdZdZ ddZy)ModelBeforeValidatorWithoutInforcyrJr=rbs r0rez(ModelBeforeValidatorWithoutInfo.__call__r2Nrfrr=r2r0rrs(    r2rc$eZdZdZ ddZy)FreeModelBeforeValidatorUA `@model_validator` decorated function signature. This is used when `mode='before'`.cyrJr=)r,rdrls r0rez!FreeModelBeforeValidator.__call__rr2N)rdrrlrnr5rrr=r2r0rrs(_   *  r2rc(eZdZdZ ddZy)ModelBeforeValidatorrcyrJr=rks r0rezModelBeforeValidator.__call__sr2Nrmrr=r2r0rrs0_     *   r2rcyrJr=rvs r0model_validatorr r2cyrJr=rs r0rr rr2cyrJr=rs r0rrrr2cdfd }|S)a"Usage docs: https://docs.pydantic.dev/2.8/concepts/validators/#model-validators Decorate model methods for validation purposes. Example usage: ```py from typing_extensions import Self from pydantic import BaseModel, ValidationError, model_validator class Square(BaseModel): width: float height: float @model_validator(mode='after') def verify_square(self) -> Self: if self.width != self.height: raise ValueError('width and height do not match') return self s = Square(width=1, height=1) print(repr(s)) #> Square(width=1.0, height=1.0) try: Square(width=1, height=2) except ValidationError as e: print(e) ''' 1 validation error for Square Value error, width and height do not match [type=value_error, input_value={'width': 1, 'height': 2}, input_type=dict] ''' ``` For more in depth examples, see [Model Validators](../concepts/validators.md#model-validators). Args: mode: A required string literal that specifies the validation mode. It can be one of the following: 'wrap', 'before', or 'after'. Returns: A decorator that can be used to decorate a function to be used as a model validator. ctj|}tj}tj||S)Nr)rrModelValidatorDecoratorInfor)rrrvs r0rzmodel_validator..decKs6  = =a @::E221h??r2)rrr5rr=)rvrs` r0rrs`@ Jr2AnyTypecLeZdZdZeddZeddZejZy) InstanceOfuGeneric type for annotating a type that is an instance of a given class. Example: ```py from pydantic import BaseModel, InstanceOf class Foo: ... class Bar(BaseModel): foo: InstanceOf[Foo] Bar(foo=Foo()) try: Bar(foo=42) except ValidationError as e: print(e) """ [ │ { │ │ 'type': 'is_instance_of', │ │ 'loc': ('foo',), │ │ 'msg': 'Input should be an instance of Foo', │ │ 'input': 42, │ │ 'ctx': {'class': 'Foo'}, │ │ 'url': 'https://errors.pydantic.dev/0.38.0/v/is_instance_of' │ } ] """ ``` c"t||fSrJ)rrcitems r0__class_getitem__zInstanceOf.__class_getitem__sT35[) )r2cddlm}tjt j |xs|} ||}tj d||d<tj||S#|$r|cYSwxYw)NrrGc||SrJr=rKs r0rNz9InstanceOf.__get_pydantic_core_schema__..!A$r2rOrR) python_schema json_schema)rSrHr is_instance_schemar get_originrTjson_or_python_schema)rcsourcer.rHinstance_of_schemaoriginal_schemas r0r1z'InstanceOf.__get_pydantic_core_schema__s >"-!?!? @T@TU[@\@f`f!g  x")&/ 7B6e6e.7"?3#88GYgvww1 *)) *sA..A87A8N)rrr5rrrr.rr5r6) r8r9r:r; classmethodrr1object__hash__r=r2r0rr]s= @  *  *  x  x&??r2rcBeZdZdZddZeddZejZy)SkipValidationaIf this is applied as an annotation (e.g., via `x: Annotated[int, SkipValidation]`), validation will be skipped. You can also use `SkipValidation[int]` as a shorthand for `Annotated[int, SkipValidation]`. This can be useful if you want to use a type annotation for documentation/IDE/type-checking purposes, and know that it is safe to skip validation for one or more of the fields. Because this converts the validation schema to `any_schema`, subsequent annotation-applied transformations may not have the expected effects. Therefore, when used, this annotation should generally be the final annotation applied to a type. c(t|tfSrJ)rrrs r0rz SkipValidation.__class_getitem__sT>#334 4r2c||tjfdg}tj|tjdS)Nc|SrJr=)_crMrs r0rNz=SkipValidation.__get_pydantic_core_schema__..s abcrasr2)js_annotation_functionsc||SrJr=rKs r0rNz=SkipValidation.__get_pydantic_core_schema__..rr2rO)metadatarR)rbuild_metadata_dictr any_schemarT)rcrr.rrs @r0r1z+SkipValidation.__get_pydantic_core_schema__sI%foO%99SsRtuH))!)MM. r2N)rrr5rr) r8r9r:r;rrr1rrr=r2r0rrs+  5    ??r2rr=) rzrr{rrvz#Literal['before', 'after', 'plain']rw bool | Noner5zRCallable[[_V2BeforeAfterOrPlainValidatorType], _V2BeforeAfterOrPlainValidatorType]) rzrr{rrvLiteral['wrap']rwrr5z6Callable[[_V2WrapValidatorType], _V2WrapValidatorType]) rzrr{rrvr~rwrr5zCallable[[Any], Any])rvrr5z|Callable[[_AnyModelWrapValidator[_ModelType]], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]])rvzLiteral['before']r5zqCallable[[_AnyModeBeforeValidator], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]])rvzLiteral['after']r5z}Callable[[_AnyModelAfterValidator[_ModelType]], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]])rvz"Literal['wrap', 'before', 'after']r5r)Rr; __future__r _annotations dataclassessys functoolsrtypesrtypingrrrr r r r pydantic_corer _core_schematyping_extensionsrrrrr4 _internalrrrrannotated_handlerserrorsr version_inforinspect_validatorr& dataclass slots_truerr?rErXr`rirpr'r) _V2Validatorr[_V2WrapValidatorr staticmethodrsr<rtrur|r~rrValidatorFunctionWrapHandlerrrrrrrrModelAfterValidatorWithoutInfoValidationInfoModelAfterValidator_AnyModelWrapValidator_AnyModeBeforeValidator_AnyModelAfterValidatorrrrrr=r2r0rsAH2 #OOO%5;;;RR4%g* 22EdE&9&D&DE4U4UF4UnEdE&9&D&DE(V(VF(VVEdE&9&D&DE0c0cF0cfEdE&9&D&DE/T/TF/Td@x@ccH..$,, .L!22 4 ,1S#s]1K\Z]_bZbMcersvew1w+xyx)0,!*& ##9;KMfg 14 # ] ]] . ]  ] X ] ] !$ A AA  A  A < A A"))K!LYL!( $ [ [[  [  [  [|\ " ~6   I I8T`Ka  HZ$8" *-  (  h  x  8 "*:, *B!C L,G,GH*TUZ1*=?\]g?hhi24WYxx 3J ?A_`jAk kl         6 ,6 6r ) 7C<(J[<0;;<9#9#=9#xw|,N[<0;;<##=#r2