o
    $6dM                     @  s  U d Z ddlmZ ddlZddlZddlmZ ddlm	Z	 ddl
mZmZmZmZmZmZ ddlmZ ddlmZ ddlmZmZmZ d	d
lmZ d	dlmZmZmZmZm Z  d	dl!m"Z" ej#dk riddlm$Z$ nddl
m$Z$ ej%Z&ej'dWddie j(G dd dZ)ej'dWddie j(G dd dZ*ej'dWddie j(G dd dZ+ej'dWddie j(G dd dZ,er
G dd de$Z-G dd de$Z.G dd de$Z/ee.ej0e-ej1f Z2ee/ej3ej4f Z5ee6eeef e7eef ee f Z8de9d < ed!e2e8Z:ed"e5e8Z;ed#d#d$dXd.d/Z<ed#d0dYd3d/Z<ed4 Z=de9d5< d6dd$dZd8d/Z<ed9Z>ed:dd;Z?G d<d= d=ej@e$e? ZAG d>d? d?e$e> ZBG d@dA dAe$e> ZCG dBdC dCe$ZDG dDdE dEe$ZEee>ge>f ZF	 ee>ejGge>f ZH	 eeCe> eBe> f ZIeeEeDf ZJeeHe> eFe> f ZKed[dGdHZLed\dKdHZLed]dNdHZLd^dQdHZLedRZMereeMd#f ZNnej'dWi e j(G dSdT dTZNereeMd#f ZOdS ej'dWi e j(G dUdV dVZOdS )_zBThis module contains related classes and functions for validation.    )annotationsN)partialmethod)FunctionType)TYPE_CHECKINGAnyCallableTypeVarUnionoverload)core_schema)	AnnotatedLiteral	TypeAlias   )GetCoreSchemaHandler)_annotated_handlers_core_metadata_decorators	_generics_internal_dataclass)PydanticUserError)      )ProtocolfrozenTc                   @  $   e Zd ZU dZded< dd
dZdS )AfterValidatora  Usage docs: https://docs.pydantic.dev/2.2/usage/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 import Annotated

        from pydantic import BaseModel, AfterValidator, 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/0.38.0/v/int_parsing"
            }
        ]
        """
        ```
    Jcore_schema.NoInfoValidatorFunction | core_schema.GeneralValidatorFunctionfuncsource_typer   handler_GetCoreSchemaHandlerreturncore_schema.CoreSchemac                 C  8   ||}t | jd}|rtj| j|dS tj| j|dS )Nafterschema)_inspect_validatorr   r   Z general_after_validator_functionZ no_info_after_validator_functionselfr   r    r'   info_arg r,   uC:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\pydantic/functional_validators.py__get_pydantic_core_schema__O   
   z+AfterValidator.__get_pydantic_core_schema__Nr   r   r    r!   r"   r#   __name__
__module____qualname____doc____annotations__r.   r,   r,   r,   r-   r   !   s   
 *r   c                   @  r   )BeforeValidatora  Usage docs: https://docs.pydantic.dev/2.2/usage/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
        ```
    r   r   r   r   r    r!   r"   r#   c                 C  r$   )Nbeforer&   )r(   r   r   Z!general_before_validator_functionZ!no_info_before_validator_functionr)   r,   r,   r-   r.   y   r/   z,BeforeValidator.__get_pydantic_core_schema__Nr0   r1   r,   r,   r,   r-   r7   X   s   
 r7   c                   @  r   )PlainValidatora8  Usage docs: https://docs.pydantic.dev/2.2/usage/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
        ```
    r   r   r   r   r    r!   r"   r#   c                 C  s(   t | jd}|rt| jS t| jS )Nplain)r(   r   r   Z general_plain_validator_functionZ no_info_plain_validator_function)r*   r   r    r+   r,   r,   r-   r.      s   z+PlainValidator.__get_pydantic_core_schema__Nr0   r1   r,   r,   r,   r-   r9      s   
 r9   c                   @  r   )WrapValidatora  Usage docs: https://docs.pydantic.dev/2.2/usage/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
    ```
    z{core_schema.NoInfoWrapValidatorFunction | core_schema.GeneralWrapValidatorFunction | core_schema.FieldWrapValidatorFunctionr   r   r   r    r!   r"   r#   c                 C  r$   )Nwrapr&   )r(   r   r   Zgeneral_wrap_validator_functionZno_info_wrap_validator_functionr)   r,   r,   r-   r.      r/   z*WrapValidator.__get_pydantic_core_schema__Nr0   r1   r,   r,   r,   r-   r;      s   
 $r;   c                   @  s   e Zd ZdddZdS )	_OnlyValueValidatorClsMethod!_OnlyValueValidatorClsMethod__clsr   #_OnlyValueValidatorClsMethod__valuer"   c                 C     d S Nr,   )r*   r>   r?   r,   r,   r-   __call__      z%_OnlyValueValidatorClsMethod.__call__N)r>   r   r?   r   r"   r   r2   r3   r4   rB   r,   r,   r,   r-   r=          r=   c                   @  s   e Zd Zd
ddZd	S )_V2ValidatorClsMethod_V2ValidatorClsMethod__clsr   "_V2ValidatorClsMethod__input_value_V2ValidatorClsMethod__info _core_schema.FieldValidationInfor"   c                 C  r@   rA   r,   )r*   rG   rH   rI   r,   r,   r-   rB      rC   z_V2ValidatorClsMethod.__call__N)rG   r   rH   r   rI   rJ   r"   r   rD   r,   r,   r,   r-   rF      rE   rF   c                   @  s   e Zd Zdd	d
ZdS )_V2WrapValidatorClsMethod_V2WrapValidatorClsMethod__clsr   &_V2WrapValidatorClsMethod__input_value$_V2WrapValidatorClsMethod__validator)_core_schema.ValidatorFunctionWrapHandler_V2WrapValidatorClsMethod__info_core_schema.ValidationInfor"   c                 C  r@   rA   r,   )r*   rL   rM   rN   rP   r,   r,   r-   rB         z"_V2WrapValidatorClsMethod.__call__N)
rL   r   rM   r   rN   rO   rP   rQ   r"   r   rD   r,   r,   r,   r-   rK      rE   rK   r   _PartialClsOrStaticMethod"_V2BeforeAfterOrPlainValidatorType_V2WrapValidatorType.)modecheck_fields__fieldstrfieldsrV   #Literal['before', 'after', 'plain']rW   bool | Noner"   RCallable[[_V2BeforeAfterOrPlainValidatorType], _V2BeforeAfterOrPlainValidatorType]c                G  r@   rA   r,   rX   rV   rW   rZ   r,   r,   r-   field_validator  rR   r_   )rW   Literal['wrap']6Callable[[_V2WrapValidatorType], _V2WrapValidatorType]c                G  r@   rA   r,   r^   r,   r,   r-   r_     rR   )r8   r%   r<   r:   FieldValidatorModesr%   Callable[[Any], Any]c                  sV   t | trtddd| gR tdd D s tdddd fdd}|S )a  Usage docs: https://docs.pydantic.dev/2.2/usage/validators/#field-validators

    Decorate methods on the class indicating that they should be used to validate fields.

    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('<field_name>', ...)`zvalidator-no-fieldscodec                 s  s    | ]}t |tV  qd S rA   )
isinstancerY   ).0fieldr,   r,   r-   	<genexpr>=  s    z"field_validator.<locals>.<genexpr>z`@field_validator` fields should be passed as separate string args. E.g. usage should be `@validator('<field_name_1>', '<field_name_2>', ...)`zvalidator-invalid-fieldsfHCallable[..., Any] | staticmethod[Any, Any] | classmethod[Any, Any, Any]r"   (_decorators.PydanticDescriptorProxy[Any]c                   s<   t | rtdddt | } t j d}t | |S )Nz8`@field_validator` cannot be applied to instance methodszvalidator-instance-methodrd   )rZ   rV   rW   )r   Zis_instance_method_from_sigr   %ensure_classmethod_based_on_signatureZFieldValidatorDecoratorInfoPydanticDescriptorProxyrj   Zdec_inforW   rZ   rV   r,   r-   decD  s   

zfield_validator.<locals>.decN)rj   rk   r"   rl   )rf   r   r   all)rX   rV   rW   rZ   rq   r,   rp   r-   r_     s   

_ModelType_ModelTypeCo)	covariantc                   @  s   e Zd ZdZ	ddd	d
ZdS )ModelWrapValidatorHandlerz[@model_validator decorated function handler argument type. This is used when `mode='wrap'`.Ninput_valuer   outer_locationstr | int | Noner"   rt   c                 C  r@   rA   r,   )r*   rw   rx   r,   r,   r-   rB   \  s   z"ModelWrapValidatorHandler.__call__rA   )rw   r   rx   ry   r"   rt   r2   r3   r4   r5   rB   r,   r,   r,   r-   rv   Y  s    rv   c                   @  s   e Zd ZdZdd
dZdS )ModelWrapValidatorWithoutInfozA @model_validator decorated function signature.
    This is used when `mode='wrap'` and the function does not have info argument.
    clstype[_ModelType]%_ModelWrapValidatorWithoutInfo__valuer   '_ModelWrapValidatorWithoutInfo__handler%ModelWrapValidatorHandler[_ModelType]r"   rs   c                 C  r@   rA   r,   )r*   r|   r~   r   r,   r,   r-   rB   g     	z&ModelWrapValidatorWithoutInfo.__call__N)r|   r}   r~   r   r   r   r"   rs   rz   r,   r,   r,   r-   r{   b      r{   c                   @  s   e Zd ZdZdddZdS )ModelWrapValidatorzQA @model_validator decorated function signature. This is used when `mode='wrap'`.r|   r}   _ModelWrapValidator__valuer   _ModelWrapValidator__handlerr   _ModelWrapValidator__inforQ   r"   rs   c                 C  r@   rA   r,   )r*   r|   r   r   r   r,   r,   r-   rB   v  s   
zModelWrapValidator.__call__N)
r|   r}   r   r   r   r   r   rQ   r"   rs   rz   r,   r,   r,   r-   r   s      r   c                   @  s   e Zd ZdZd	ddZdS )
ModelBeforeValidatorWithoutInfozA @model_validator decorated function signature.
    This is used when `mode='before'` and the function does not have info argument.
    r|   r   '_ModelBeforeValidatorWithoutInfo__valuer"   c                 C  r@   rA   r,   )r*   r|   r   r,   r,   r-   rB     s   z(ModelBeforeValidatorWithoutInfo.__call__N)r|   r   r   r   r"   r   rz   r,   r,   r,   r-   r     r   r   c                   @  s   e Zd ZdZddd	Zd
S )ModelBeforeValidatorzUA `@model_validator` decorated function signature. This is used when `mode='before'`.r|   r   _ModelBeforeValidator__value_ModelBeforeValidator__inforQ   r"   c                 C  r@   rA   r,   )r*   r|   r   r   r,   r,   r-   rB     r   zModelBeforeValidator.__call__N)r|   r   r   r   r   rQ   r"   r   rz   r,   r,   r,   r-   r     r   r   pCallable[[_AnyModelWrapValidator], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]c                 C  r@   rA   r,   rV   r,   r,   r-   model_validator     r   Literal['before']qCallable[[_AnyModeBeforeValidator], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]c                 C  r@   rA   r,   r   r,   r,   r-   r     r   Literal['after']}Callable[[_AnyModelAfterValidator[_ModelType]], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]c                 C  r@   rA   r,   r   r,   r,   r-   r     rR   "Literal['wrap', 'before', 'after']r   c                   s   d fdd}|S )	a@  Decorate model methods for validation purposes.

    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.
    rj   r   r"   rl   c                   s"   t | } t j d}t | |S )Nr   )r   rm   ZModelValidatorDecoratorInforn   ro   r   r,   r-   rq     s   
zmodel_validator.<locals>.decN)rj   r   r"   rl   r,   )rV   rq   r,   r   r-   r     s   AnyTypec                   @  s2   e Zd ZdZedddZedddZejZdS )
InstanceOfu  Generic 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'
                │   }
                ]
                """
            ```
        itemr   r"   c                 C  s   t ||  f S rA   )r   r|   r   r,   r,   r-   __class_getitem__  s   zInstanceOf.__class_getitem__sourcer   r    (_annotated_handlers.GetCoreSchemaHandlerr#   c                 C  sh   ddl m} tt|p|}z||}W n |y!   | Y S w tjdd |d|d< tj||dS )Nr   )PydanticSchemaGenerationErrorc                 S  s   || S rA   r,   )vhr,   r,   r-   <lambda>!      z9InstanceOf.__get_pydantic_core_schema__.<locals>.<lambda>)functionr'   serialization)Zpython_schemaZjson_schema)Zpydanticr   r   Zis_instance_schemar   
get_originZ#wrap_serializer_function_ser_schemaZjson_or_python_schema)r|   r   r    r   Zinstance_of_schemaoriginal_schemar,   r,   r-   r.     s   
z'InstanceOf.__get_pydantic_core_schema__N)r   r   r"   r   r   r   r    r   r"   r#   )	r2   r3   r4   r5   classmethodr   r.   object__hash__r,   r,   r,   r-   r     s     
r   c                   @  s.   e Zd ZdZdddZedddZejZdS )SkipValidationa  If 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.
        r   r   r"   c                 C  s   t |t f S rA   )r   r   r   r,   r,   r-   r   9  s   z SkipValidation.__class_getitem__r   r    r   r#   c                   s,   || t j fddgd}tj| dS )Nc                   s   | S rA   r,   )Z_cr   r   r,   r-   r   A  r   z=SkipValidation.__get_pydantic_core_schema__.<locals>.<lambda>)Zjs_annotation_functions)metadatar   )r   Zbuild_metadata_dictr   Z
any_schema)r|   r   r    r   r,   r   r-   r.   <  s   z+SkipValidation.__get_pydantic_core_schema__N)r   r   r"   r   r   )	r2   r3   r4   r5   r   r   r.   r   r   r,   r,   r,   r-   r   ,  s    

r   r,   )
rX   rY   rZ   rY   rV   r[   rW   r\   r"   r]   )
rX   rY   rZ   rY   rV   r`   rW   r\   r"   ra   )
rX   rY   rZ   rY   rV   rb   rW   r\   r"   rc   )rV   r`   r"   r   )rV   r   r"   r   )rV   r   r"   r   )rV   r   r"   r   )Pr5   
__future__r   Z_annotationsdataclassessys	functoolsr   typesr   typingr   r   r   r   r	   r
   Zpydantic_corer   Z_core_schemaZtyping_extensionsr   r   r    r   r!   	_internalr   r   r   r   r   errorsr   version_infor   Zinspect_validatorr(   	dataclassZ
slots_truer   r7   r9   r;   r=   rF   rK   ZFieldValidatorFunctionZNoInfoValidatorFunctionZ_V2ValidatorZGeneralWrapValidatorFunctionZFieldWrapValidatorFunctionZ_V2WrapValidatorr   staticmethodrS   r6   rT   rU   r_   rb   rs   rt   ZValidatorFunctionWrapHandlerrv   r{   r   r   r   ZModelAfterValidatorWithoutInfoZValidationInfoZModelAfterValidatorZ_AnyModelWrapValidatorZ_AnyModeBeforeValidatorZ_AnyModelAfterValidatorr   r   r   r   r,   r,   r,   r-   <module>   s     
6)"4
,		9	
	>