o
    FÊÆhW  ã                   @  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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  d	d
l!mZ d	dl"m#Z# ej$dk rod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%ƒZ0ee/ej1e.ej2f Z3ee0ej4f Z5ee6eeef e7eef ee f Z8de9d < ed!e3e8ƒ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�rÂeeMd#f ZNnej(dWi e j)¤ŽG dSdT„ dTƒƒZNe�rÝe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ÚcastÚoverload)Úcore_schema)Ú	AnnotatedÚLiteralÚ	TypeAliasé   )ÚGetCoreSchemaHandler)Ú_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 )ÚAfterValidatora8  Usage docs: https://docs.pydantic.dev/2.5/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.WithInfoValidatorFunctionÚfuncÚsource_typer   ÚhandlerÚ_GetCoreSchemaHandlerÚreturnúcore_schema.CoreSchemac                 C  óT   ||ƒ}t | jdƒ}|rttj| jƒ}tj|||jd�S ttj| jƒ}tj||d�S )NÚafter©ÚschemaÚ
field_name©r'   )	Ú_inspect_validatorr   r
   r   ÚWithInfoValidatorFunctionÚ"with_info_after_validator_functionr(   ÚNoInfoValidatorFunctionÚ no_info_after_validator_function©Úselfr   r    r'   Úinfo_argr   © r2   úk/var/www/html/HyperOracle/crypto_trader/venv/lib/python3.10/site-packages/pydantic/functional_validators.pyÚ__get_pydantic_core_schema__I   ó   z+AfterValidator.__get_pydantic_core_schema__N©r   r   r    r!   r"   r#   ©Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r4   r2   r2   r2   r3   r      s   
 )r   c                   @  r   )ÚBeforeValidatoraÈ  Usage docs: https://docs.pydantic.dev/2.5/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
        ```
    r   r   r   r   r    r!   r"   r#   c                 C  r$   )NÚbeforer&   r)   )	r*   r   r
   r   r+   Ú#with_info_before_validator_functionr(   r-   Ú!no_info_before_validator_functionr/   r2   r2   r3   r4   u   r5   z,BeforeValidator.__get_pydantic_core_schema__Nr6   r7   r2   r2   r2   r3   r=   T   s   
 r=   c                   @  r   )ÚPlainValidatora;  Usage docs: https://docs.pydantic.dev/2.5/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
        ```
    r   r   r   r   r    r!   r"   r#   c                 C  sF   t | jdƒ}|rttj| jƒ}tj||jd�S ttj| jƒ}t |¡S )NÚplain)r(   )	r*   r   r
   r   r+   Ú"with_info_plain_validator_functionr(   r-   Ú no_info_plain_validator_function)r0   r   r    r1   r   r2   r2   r3   r4   ›   s   
z+PlainValidator.__get_pydantic_core_schema__Nr6   r7   r2   r2   r2   r3   rA   €   s   
 rA   c                   @  r   )ÚWrapValidatora  Usage docs: https://docs.pydantic.dev/2.5/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.WithInfoWrapValidatorFunctionr   r   r   r    r!   r"   r#   c                 C  r$   )NÚwrapr&   r)   )	r*   r   r
   r   ÚWithInfoWrapValidatorFunctionÚ!with_info_wrap_validator_functionr(   ÚNoInfoWrapValidatorFunctionÚno_info_wrap_validator_functionr/   r2   r2   r3   r4   Í   r5   z*WrapValidator.__get_pydantic_core_schema__Nr6   r7   r2   r2   r2   r3   rE   ¥   s   
 $rE   c                   @  s   e Zd Zddd„ZdS )	Ú_OnlyValueValidatorClsMethodÚ!_OnlyValueValidatorClsMethod__clsr   Ú#_OnlyValueValidatorClsMethod__valuer"   c                 C  ó   d S ©Nr2   )r0   rL   rM   r2   r2   r3   Ú__call__Û   ó   z%_OnlyValueValidatorClsMethod.__call__N)rL   r   rM   r   r"   r   ©r8   r9   r:   rP   r2   r2   r2   r3   rK   Ú   ó    rK   c                   @  s   e Zd Zd
dd„Zd	S )Ú_V2ValidatorClsMethodÚ_V2ValidatorClsMethod__clsr   Ú"_V2ValidatorClsMethod__input_valueÚ_V2ValidatorClsMethod__infoú_core_schema.ValidationInfor"   c                 C  rN   rO   r2   )r0   rU   rV   rW   r2   r2   r3   rP   ß   rQ   z_V2ValidatorClsMethod.__call__N)rU   r   rV   r   rW   rX   r"   r   rR   r2   r2   r2   r3   rT   Þ   rS   rT   c                   @  s   e Zd Zdd	d
„ZdS )Ú_V2WrapValidatorClsMethodÚ_V2WrapValidatorClsMethod__clsr   Ú&_V2WrapValidatorClsMethod__input_valueÚ$_V2WrapValidatorClsMethod__validatorú)_core_schema.ValidatorFunctionWrapHandlerÚ_V2WrapValidatorClsMethod__inforX   r"   c                 C  rN   rO   r2   )r0   rZ   r[   r\   r^   r2   r2   r3   rP   ã   ó   z"_V2WrapValidatorClsMethod.__call__N)
rZ   r   r[   r   r\   r]   r^   rX   r"   r   rR   r2   r2   r2   r3   rY   â   rS   rY   r   Ú_PartialClsOrStaticMethodÚ"_V2BeforeAfterOrPlainValidatorTypeÚ_V2WrapValidatorType.)ÚmodeÚcheck_fieldsÚ__fieldÚstrÚfieldsrc   ú#Literal['before', 'after', 'plain']rd   úbool | Noner"   úRCallable[[_V2BeforeAfterOrPlainValidatorType], _V2BeforeAfterOrPlainValidatorType]c                G  rN   rO   r2   ©re   rc   rd   rg   r2   r2   r3   Úfield_validator  r_   rl   )rd   úLiteral['wrap']ú6Callable[[_V2WrapValidatorType], _V2WrapValidatorType]c                G  rN   rO   r2   rk   r2   r2   r3   rl     r_   )r>   r%   rF   rB   Ú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.5/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('<field_name>', ...)`zvalidator-no-fields©Úcodec                 s  s   � | ]}t |tƒV  qd S rO   )Ú
isinstancerf   )Ú.0Úfieldr2   r2   r3   Ú	<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ÚfúHCallable[..., 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-methodrq   )rg   rc   rd   )r   Úis_instance_method_from_sigr   Ú%ensure_classmethod_based_on_signatureÚFieldValidatorDecoratorInfoÚPydanticDescriptorProxy©rw   Údec_info©rd   rg   rc   r2   r3   Údece  s   
ÿ
zfield_validator.<locals>.decN)rw   rx   r"   ry   )rs   r   r   Úall)re   rc   rd   rg   r�   r2   r€   r3   rl     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"   r„   c                 C  rN   rO   r2   )r0   r‡   rˆ   r2   r2   r3   rP   }  s   z"ModelWrapValidatorHandler.__call__rO   )r‡   r   rˆ   r‰   r"   r„   ©r8   r9   r:   r;   rP   r2   r2   r2   r3   r†   z  s    ÿr†   c                   @  s   e Zd ZdZdd
d„ZdS )ÚModelWrapValidatorWithoutInfoz‡A @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"   rƒ   c                 C  rN   rO   r2   )r0   rŒ   rŽ   r�   r2   r2   r3   rP   ˆ  ó   	z&ModelWrapValidatorWithoutInfo.__call__N)rŒ   r�   rŽ   r   r�   r�   r"   rƒ   rŠ   r2   r2   r2   r3   r‹   ƒ  ó    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__inforX   r"   rƒ   c                 C  rN   rO   r2   )r0   rŒ   r”   r•   r–   r2   r2   r3   rP   —  s   
zModelWrapValidator.__call__N)
rŒ   r�   r”   r   r•   r�   r–   rX   r"   rƒ   rŠ   r2   r2   r2   r3   r“   ”  ó    r“   c                   @  s   e Zd ZdZd	dd„ZdS )
ÚModelBeforeValidatorWithoutInfoz‰A @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  rN   rO   r2   )r0   rŒ   r™   r2   r2   r3   rP   ©  s   z(ModelBeforeValidatorWithoutInfo.__call__N)rŒ   r   r™   r   r"   r   rŠ   r2   r2   r2   r3   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__inforX   r"   c                 C  rN   rO   r2   )r0   rŒ   r›   rœ   r2   r2   r3   rP   ·  r‘   zModelBeforeValidator.__call__N)rŒ   r   r›   r   rœ   rX   r"   r   rŠ   r2   r2   r2   r3   rš   ´  r—   rš   ú|Callable[[_AnyModelWrapValidator[_ModelType]], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]c                 C  rN   rO   r2   ©rc   r2   r2   r3   Úmodel_validatorÐ  r_   rŸ   úLiteral['before']úqCallable[[_AnyModeBeforeValidator], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]c                 C  rN   rO   r2   rž   r2   r2   r3   rŸ   Ú  s   úLiteral['after']ú}Callable[[_AnyModelAfterValidator[_ModelType]], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]c                 C  rN   rO   r2   rž   r2   r2   r3   rŸ   â  r_   ú"Literal['wrap', 'before', 'after']r   c                   s   d‡ fdd„}|S )	aÒ  Usage docs: https://docs.pydantic.dev/2.5/concepts/validators/#model-validators

    Decorate model methods for validation purposes.

    Example usage:
    ```py
    from typing import Optional

    from pydantic import BaseModel, ValidationError, model_validator

    class Square(BaseModel):
    width: float
    height: float

    @model_validator(mode='after')
    def verify_square(self) -> 'Rectangle':
        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
        __root__
          width and height do not match (type=value_error)
        '''
    ```

    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.
    rw   r   r"   ry   c                   s"   t  | ¡} t jˆ d�}t  | |¡S )Nrž   )r   r{   ÚModelValidatorDecoratorInfor}   r~   rž   r2   r3   r�     s   
zmodel_validator.<locals>.decN)rw   r   r"   ry   r2   )rc   r�   r2   rž   r3   rŸ   ì  s   1Ú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 rO   )r   ©rŒ   r¨   r2   r2   r3   Ú__class_getitem__Q  s   zInstanceOf.__class_getitem__Úsourcer   r    r   r#   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 rO   r2   ©ÚvÚhr2   r2   r3   Ú<lambda>e  ó    z9InstanceOf.__get_pydantic_core_schema__.<locals>.<lambda>©Úfunctionr'   Úserialization)Úpython_schemaÚjson_schema)Úpydanticr¬   r   Úis_instance_schemar   Ú
get_originÚ#wrap_serializer_function_ser_schemaÚjson_or_python_schema)rŒ   r«   r    r¬   Úinstance_of_schemaÚoriginal_schemar2   r2   r3   r4   U  s   þ
ÿz'InstanceOf.__get_pydantic_core_schema__N)r¨   r¦   r"   r¦   ©r«   r   r    r   r"   r#   )	r8   r9   r:   r;   Úclassmethodrª   r4   ÚobjectÚ__hash__r2   r2   r2   r3   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 rO   )r   rÃ   r©   r2   r2   r3   rª   }  s   z SkipValidation.__class_getitem__r«   r    r   r#   c                   s:   ||ƒ‰ t j‡ fdd„gd�}tj|tjdd„ ˆ d�d�S )Nc                   s   |ˆ ƒS rO   r2   )Ú_cr°   ©r¾   r2   r3   r±   ƒ  r²   z=SkipValidation.__get_pydantic_core_schema__.<locals>.<lambda>)Újs_annotation_functionsc                 S  r­   rO   r2   r®   r2   r2   r3   r±   ‡  r²   r³   )Úmetadatarµ   )r   Úbuild_metadata_dictr   Ú
any_schemar»   )rŒ   r«   r    rÇ   r2   rÅ   r3   r4   €  s   ÿþz+SkipValidation.__get_pydantic_core_schema__N)r¨   r   r"   r   r¿   )	r8   r9   r:   r;   rª   rÀ   r4   rÁ   rÂ   r2   r2   r2   r3   rÃ   p  s    


rÃ   r2   )
re   rf   rg   rf   rc   rh   rd   ri   r"   rj   )
re   rf   rg   rf   rc   rm   rd   ri   r"   rn   )
re   rf   rg   rf   rc   ro   rd   ri   r"   rp   )rc   rm   r"   r�   )rc   r    r"   r¡   )rc   r¢   r"   r£   )rc   r¤   r"   r   )Pr;   Ú
__future__r   Ú_annotationsÚdataclassesÚsysÚ	functoolsr   Útypesr   Útypingr   r   r   r   r	   r
   r   Úpydantic_corer   Ú_core_schemaÚtyping_extensionsr   r   r   Ú r   r!   Ú	_internalr   r   r   r   Úannotated_handlersÚerrorsr   Úversion_infor   Úinspect_validatorr*   Ú	dataclassÚ
slots_truer   r=   rA   rE   rK   rT   rY   r+   r-   Ú_V2ValidatorrG   Ú_V2WrapValidatorrÀ   Ústaticmethodr`   r<   ra   rb   rl   ro   rƒ   r„   ÚValidatorFunctionWrapHandlerr†   r‹   r“   r˜   rš   ÚModelAfterValidatorWithoutInfoÚValidationInfoÚModelAfterValidatorÚ_AnyModelWrapValidatorÚ_AnyModeBeforeValidatorÚ_AnyModelAfterValidatorrŸ   r¦   r§   rÃ   r2   r2   r2   r3   Ú<module>   s´    $
7+$2
ýÿÿÿ,ýü	ü	ü]		
	:<