o
    ¨ÝjÉ�  ã                   @  s\  U d Z ddlmZ ddl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mZ ddlmZmZ ddlmZmZ d	d
lmZmZ d	dlmZ d	dlm Z  d	dl!m"Z" d	dlm#Z#m$Z$ ej%dk rsddlm&Z& nddlm&Z& ej'Z(ej)ddd�G dd„ dƒƒZ*ej)ddd�G dd„ dƒƒZ+ej)ddd�G dd„ dƒƒZ,ej)ddd�G dd„ dƒƒZ-e�rG dd„ de&ƒZ.G dd„ de&ƒZ/G dd „ d e&ƒZ0G d!d"„ d"e&ƒZ1e/ej2B e.B ej3B Z4d#e5d$< e1ej6B e0B ej7B Z8d#e5d%< e9eeef e:eef B e
e B Z;d#e5d&< ed'e4e;B d(�Z<ed)e8e;B d(�Z=ed* Z>d#e5d+< ed,d,d-œdnd9d:„ƒZ?ed,d,d-œdod=d:„ƒZ?ed,d,d>œdpd@d:„ƒZ?dAdedBœdqdDd:„Z?edEƒZ@edFddG�ZAG dHdI„ dIejBe&eA ƒZCG dJdK„ dKe&e@ ƒZDG dLdM„ dMe&e@ ƒZEG dNdO„ dOe&ƒZFG dPdQ„ dQe&ƒZGG dRdS„ dSe&ƒZHG dTdU„ dUe&ƒZIee@ge@f ZJd#e5dV< 	 ee@ejKe ge@f ZLd#e5dW< 	 eEe@ eDe@ B ZMd#e5dX< eHeIB eFB eGB ZNd#e5dY< eLe@ eJe@ B ZOd#e5dZ< edrd\d]„ƒZPedsd`d]„ƒZPedtdbd]„ƒZPduddd]„ZPedeƒZQe�rýeeQd,f ZRnej)ddf�G dgdh„ dhƒƒZRe�reeQd,f ZSnej)ddf�G didj„ djƒƒZSedkƒZTG dldm„ dmƒZUdS )vzBThis module contains related classes and functions for validation.é    )ÚannotationsN)ÚCallable)Úpartialmethod)ÚTYPE_CHECKINGÚ	AnnotatedÚAnyÚLiteralÚ	TypeAliasÚTypeVarÚcastÚoverload)ÚPydanticUndefinedÚcore_schema)ÚSelfÚTypeFormé   )Ú_decoratorsÚ	_generics)ÚGetCoreSchemaHandler)ÚPydanticUserError)Úversion_short)ÚArbitraryTypeWarningÚPydanticDeprecatedSince212)é   é   )ÚProtocolT)ÚfrozenÚslotsc                   @  s2   e Zd ZU dZded< dd
d„Zeddd„ƒZdS )ÚAfterValidatoraT  !!! abstract "Usage Documentation"
        [field *after* validators](../concepts/validators.md#field-after-validator)

    A metadata class that indicates that a validation should be applied **after** the inner validation logic.

    Attributes:
        func: The validator function.

    Example:
        ```python
        from typing 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   Úhandlerr   Úreturnúcore_schema.CoreSchemac                 C  sT   ||ƒ}t | jddd�}|rttj| jƒ}tj||d�S ttj| jƒ}tj||d�S )NÚafterÚfield©ÚmodeÚtype©Úschema)Ú_inspect_validatorr    r   r   ÚWithInfoValidatorFunctionZ"with_info_after_validator_functionÚNoInfoValidatorFunctionÚ no_info_after_validator_function)Úselfr!   r"   r+   Úinfo_argr    © r2   úY/var/www/html/chatgpt/venv/lib/python3.10/site-packages/pydantic/functional_validators.pyÚ__get_pydantic_core_schema__K   s   z+AfterValidator.__get_pydantic_core_schema__Ú	decoratorú>_decorators.Decorator[_decorators.FieldValidatorDecoratorInfo]r   c                 C  s   | |j d�S )N©r    r7   ©Úclsr5   r2   r2   r3   Ú_from_decoratorU   s   zAfterValidator._from_decoratorN©r!   r   r"   r   r#   r$   ©r5   r6   r#   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r4   Úclassmethodr:   r2   r2   r2   r3   r      s   
 *

r   c                   @  ó>   e Zd ZU dZded< eZded< ddd„Zeddd„ƒZ	dS )ÚBeforeValidatora„  !!! abstract "Usage Documentation"
        [field *before* validators](../concepts/validators.md#field-before-validator)

    A metadata class that indicates that a validation should be applied **before** the inner validation logic.

    Attributes:
        func: The validator function.
        json_schema_input_type: The input type used to generate the appropriate
            JSON Schema (in validation mode). The actual input type is `Any`.

    Example:
        ```python
        from typing 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   Újson_schema_input_typer!   r"   r   r#   r$   c                 C  ór   ||ƒ}| j tu rd n| | j ¡}t| jddd�}|r*ttj| jƒ}tj|||d�S ttj	| jƒ}tj
|||d�S )NÚbeforer&   r'   ©r+   Újson_schema_input_schema)rE   r   Úgenerate_schemar,   r    r   r   r-   Z#with_info_before_validator_functionr.   Z!no_info_before_validator_function©r0   r!   r"   r+   Úinput_schemar1   r    r2   r2   r3   r4      s"   
ÿ
ýýÿz,BeforeValidator.__get_pydantic_core_schema__r5   r6   r   c                 C  ó   | |j |jjd�S ©N)r    rE   ©r    ÚinforE   r8   r2   r2   r3   r:   •   ó   þzBeforeValidator._from_decoratorNr;   r<   ©
r=   r>   r?   r@   rA   r   rE   r4   rB   r:   r2   r2   r2   r3   rD   Z   s   
  
rD   c                   @  rC   )ÚPlainValidatoraw  !!! abstract "Usage Documentation"
        [field *plain* validators](../concepts/validators.md#field-plain-validator)

    A metadata class that indicates that a validation should be applied **instead** of the inner validation logic.

    !!! note
        Before v2.9, `PlainValidator` wasn't always compatible with JSON Schema generation for `mode='validation'`.
        You can now use the `json_schema_input_type` argument to specify the input type of the function
        to be used in the JSON schema when `mode='validation'` (the default). See the example below for more details.

    Attributes:
        func: The validator function.
        json_schema_input_type: The input type used to generate the appropriate
            JSON Schema (in validation mode). The actual input type is `Any`.

    Example:
        ```python
        from typing import Annotated

        from pydantic import BaseModel, PlainValidator

        def validate(v: object) -> int:
            if not isinstance(v, (int, str)):
                raise ValueError(f'Expected int or str, got {type(v)}')

            return int(v) + 1

        MyInt = Annotated[
            int,
            PlainValidator(validate, json_schema_input_type=str | int),  # (1)!
        ]

        class Model(BaseModel):
            a: MyInt

        print(Model(a='1').a)
        #> 2

        print(Model(a=1).a)
        #> 2
        ```

        1. In this example, we've specified the `json_schema_input_type` as `Union[str, int]` which indicates to the JSON schema
        generator that in validation mode, the input type for the `a` field can be either a [`str`][] or an [`int`][].
    r   r    r   rE   r!   r"   r   r#   r$   c           	   	   C  s®   ddl m} z||ƒ}| dtjdd„ || |¡d�¡}W n |y(   d }Y nw | | j¡}t| jddd	�}|rHt	tj
| jƒ}tj|||d
�S t	tj| jƒ}tj|||d
�S )Nr   )ÚPydanticSchemaGenerationErrorÚserializationc                 S  ó   || ƒS ©Nr2   ©ÚvÚhr2   r2   r3   Ú<lambda>ß   ó    z=PlainValidator.__get_pydantic_core_schema__.<locals>.<lambda>)Úfunctionr+   Zreturn_schemaÚplainr&   r'   )rU   rI   )ZpydanticrT   Úgetr   Ú#wrap_serializer_function_ser_schemarJ   rE   r,   r    r   r-   Z"with_info_plain_validator_functionr.   Z no_info_plain_validator_function)	r0   r!   r"   rT   r+   rU   rL   r1   r    r2   r2   r3   r4   Ð   s:   ýþÿýýz+PlainValidator.__get_pydantic_core_schema__r5   r6   r   c                 C  rM   rN   rO   r8   r2   r2   r3   r:   ù   rQ   zPlainValidator._from_decoratorNr;   r<   )
r=   r>   r?   r@   rA   r   rE   r4   rB   r:   r2   r2   r2   r3   rS   �   s   
 .
)rS   c                   @  rC   )ÚWrapValidatoraÒ  !!! abstract "Usage Documentation"
        [field *wrap* validators](../concepts/validators.md#field-wrap-validator)

    A metadata class that indicates that a validation should be applied **around** the inner validation logic.

    Attributes:
        func: The validator function.
        json_schema_input_type: The input type used to generate the appropriate
            JSON Schema (in validation mode). The actual input type is `Any`.

    ```python
    from datetime import datetime
    from typing 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   rE   r!   r"   r   r#   r$   c                 C  rF   )NÚwrapr&   r'   rH   )rE   r   rJ   r,   r    r   r   ÚWithInfoWrapValidatorFunctionZ!with_info_wrap_validator_functionÚNoInfoWrapValidatorFunctionZno_info_wrap_validator_functionrK   r2   r2   r3   r4   ,  s&   
ÿ
ýýýz*WrapValidator.__get_pydantic_core_schema__r5   r6   r   c                 C  rM   rN   rO   r8   r2   r2   r3   r:   D  rQ   zWrapValidator._from_decoratorNr;   r<   rR   r2   r2   r2   r3   ra     s   
 &
ra   c                   @  s   e Zd Zddd„ZdS )	Ú_OnlyValueValidatorClsMethodr9   r   Úvaluer#   c                C  ó   d S rW   r2   ©r0   r9   rf   r2   r2   r3   Ú__call__O  ó    z%_OnlyValueValidatorClsMethod.__call__N©r9   r   rf   r   r#   r   ©r=   r>   r?   ri   r2   r2   r2   r3   re   N  ó    re   c                   @  ó   e Zd Zd
dd„Zd	S )Ú_V2ValidatorClsMethodr9   r   rf   rP   úcore_schema.ValidationInfo[Any]r#   c                C  rg   rW   r2   ©r0   r9   rf   rP   r2   r2   r3   ri   R  rj   z_V2ValidatorClsMethod.__call__N©r9   r   rf   r   rP   rp   r#   r   rl   r2   r2   r2   r3   ro   Q  rm   ro   c                   @  rn   )Ú _OnlyValueWrapValidatorClsMethodr9   r   rf   r"   ú(core_schema.ValidatorFunctionWrapHandlerr#   c                C  rg   rW   r2   ©r0   r9   rf   r"   r2   r2   r3   ri   U  rj   z)_OnlyValueWrapValidatorClsMethod.__call__N)r9   r   rf   r   r"   rt   r#   r   rl   r2   r2   r2   r3   rs   T  rm   rs   c                   @  s   e Zd Zdd	d
„ZdS )Ú_V2WrapValidatorClsMethodr9   r   rf   r"   rt   rP   rp   r#   c                C  rg   rW   r2   ©r0   r9   rf   r"   rP   r2   r2   r3   ri   X  ó   z"_V2WrapValidatorClsMethod.__call__N)
r9   r   rf   r   r"   rt   rP   rp   r#   r   rl   r2   r2   r2   r3   rv   W  rm   rv   r	   Ú_V2ValidatorÚ_V2WrapValidatorÚ_PartialClsOrStaticMethodÚ"_V2BeforeAfterOrPlainValidatorType)ÚboundÚ_V2WrapValidatorType)rG   r%   rb   r^   ÚFieldValidatorModes.)Úcheck_fieldsrE   r&   ÚstrÚfieldsr(   úLiteral['wrap']r€   úbool | NonerE   r   r#   ú6Callable[[_V2WrapValidatorType], _V2WrapValidatorType]c               G  rg   rW   r2   ©r&   r(   r€   rE   r‚   r2   r2   r3   Úfield_validatorz  ó   r‡   úLiteral['before', 'plain']úRCallable[[_V2BeforeAfterOrPlainValidatorType], _V2BeforeAfterOrPlainValidatorType]c               G  rg   rW   r2   r†   r2   r2   r3   r‡   …  rˆ   )r(   r€   úLiteral['after']c               G  rg   rW   r2   )r&   r(   r€   r‚   r2   r2   r3   r‡   �  rx   r%   )r(   r€   rE   úCallable[[Any], Any]c                 s–   t | ƒs	t| tƒrtddd�‚ˆdvr ˆtur tdˆ›�dd�‚ˆtu r*ˆdkr*t‰| gˆ¢R ‰tdd	„ ˆD ƒƒs?td
dd�‚d‡ ‡‡‡fdd„}|S )uÆ  !!! abstract "Usage Documentation"
        [field validators](../concepts/validators.md#field-validators)

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

    Example usage:
    ```python
    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).

    Errors raised in a field validator become part of the model's
    [`ValidationError`][pydantic_core.ValidationError]. In a running application,
    [Logfire](../integrations/logfire.md) can record the input each failed validation rejected â€” see
    [Troubleshooting validation errors](../errors/troubleshooting.md).

    Args:
        *fields: The field names the validator should apply to.
        mode: Specifies whether to validate the fields before or after validation.
        check_fields: Whether to check that the fields actually exist on the model.
        json_schema_input_type: The input type of the function. This is only used to generate
            the appropriate JSON Schema (in validation mode) and can only specified
            when `mode` is either `'before'`, `'plain'` or `'wrap'`.

    Raises:
        PydanticUserError:
            - If the decorator is used without any arguments (at least one field name must be provided).
            - If the provided field names are not strings.
            - If `json_schema_input_type` is provided with an unsupported `mode`.
            - If the decorator is applied to an instance method.
    z�The `@field_validator` decorator cannot be used without arguments, at least one field must be provided. For example: `@field_validator('<field_name>', ...)`.zdecorator-missing-arguments©Úcode)rG   r^   rb   z;`json_schema_input_type` can't be used when mode is set to zvalidator-input-typer^   c                 s  s   � | ]}t |tƒV  qd S rW   )Ú
isinstancer�   )Ú.0r&   r2   r2   r3   Ú	<genexpr>ð  s   € z"field_validator.<locals>.<genexpr>z™The provided field names to the `@field_validator` decorator should be strings. For example: `@field_validator('<field_name_1>', '<field_name_2>', ...).`zdecorator-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 )NzFThe `@field_validator` decorator cannot be applied to instance methodszvalidator-instance-methodr�   )r‚   r(   r€   rE   )r   Zis_instance_method_from_sigr   Ú%ensure_classmethod_based_on_signatureZFieldValidatorDecoratorInfoÚPydanticDescriptorProxy©r’   Zdec_info©r€   r‚   rE   r(   r2   r3   Údec÷  s   
þ
ÿzfield_validator.<locals>.decN)r’   r“   r#   r”   )Úcallabler�   rB   r   r   r   Úall)r&   r(   r€   rE   r‚   r™   r2   r˜   r3   r‡   š  s(   EýþýÚ
_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'`.Nrf   r   Úouter_locationústr | int | Noner#   r�   c                C  rg   rW   r2   )r0   rf   r    r2   r2   r3   ri     ó   z"ModelWrapValidatorHandler.__call__rW   )rf   r   r    r¡   r#   r�   ©r=   r>   r?   r@   ri   r2   r2   r2   r3   rŸ     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.
    r9   útype[_ModelType]rf   r   r"   ú%ModelWrapValidatorHandler[_ModelType]r#   rœ   c                C  rg   rW   r2   ru   r2   r2   r3   ri      ó   	z&ModelWrapValidatorWithoutInfo.__call__N)r9   r¥   rf   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 )ÚModelWrapValidatorzSA `@model_validator` decorated function signature. This is used when `mode='wrap'`.r9   r¥   rf   r   r"   r¦   rP   úcore_schema.ValidationInfor#   rœ   c                C  rg   rW   r2   rw   r2   r2   r3   ri   /  s   
zModelWrapValidator.__call__N)
r9   r¥   rf   r   r"   r¦   rP   rª   r#   rœ   r£   r2   r2   r2   r3   r©   ,  ó    r©   c                   @  s   e Zd ZdZddd„ZdS )	Ú#FreeModelBeforeValidatorWithoutInfoú‹A `@model_validator` decorated function signature.
    This is used when `mode='before'` and the function does not have info argument.
    rf   r   r#   c                C  rg   rW   r2   )r0   rf   r2   r2   r3   ri   A  rx   z,FreeModelBeforeValidatorWithoutInfo.__call__N)rf   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 )
ÚModelBeforeValidatorWithoutInfor­   r9   r   rf   r#   c                C  rg   rW   r2   rh   r2   r2   r3   ri   P  rˆ   z(ModelBeforeValidatorWithoutInfo.__call__Nrk   r£   r2   r2   r2   r3   r®   K  r¨   r®   c                   @  s   e Zd ZdZd
dd„Zd	S )ÚFreeModelBeforeValidatorúUA `@model_validator` decorated function signature. This is used when `mode='before'`.rf   r   rP   rp   r#   c                C  rg   rW   r2   )r0   rf   rP   r2   r2   r3   ri   ^  rˆ   z!FreeModelBeforeValidator.__call__N)rf   r   rP   rp   r#   r   r£   r2   r2   r2   r3   r¯   [  r«   r¯   c                   @  s   e Zd ZdZddd	„Zd
S )ÚModelBeforeValidatorr°   r9   r   rf   rP   rp   r#   c                C  rg   rW   r2   rq   r2   r2   r3   ri   l  r§   zModelBeforeValidator.__call__Nrr   r£   r2   r2   r2   r3   r±   i  r«   r±   ÚModelAfterValidatorWithoutInfoÚModelAfterValidatorÚ_AnyModelWrapValidatorÚ_AnyModelBeforeValidatorÚ_AnyModelAfterValidatorú|Callable[[_AnyModelWrapValidator[_ModelType]], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]c                 C  rg   rW   r2   ©r(   r2   r2   r3   Úmodel_validatorŠ  r¢   r¹   úLiteral['before']úrCallable[[_AnyModelBeforeValidator], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]c                 C  rg   rW   r2   r¸   r2   r2   r3   r¹   “  r¢   ú}Callable[[_AnyModelAfterValidator[_ModelType]], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]c                 C  rg   rW   r2   r¸   r2   r2   r3   r¹   œ  r¢   ú"Literal['wrap', 'before', 'after']c                   s   d‡ fdd„}|S )	aô  !!! abstract "Usage Documentation"
        [Model Validators](../concepts/validators.md#model-validators)

    Decorate model methods for validation purposes.

    Example usage:
    ```python
    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).

    Cross-field rules like the one above tend to fail on combinations of values you didn't anticipate.
    The resulting [`ValidationError`][pydantic_core.ValidationError] includes the input that failed;
    [Logfire](../integrations/logfire.md) can retain these failures with their trace context so you can
    investigate patterns in a running application (see
    [Troubleshooting validation errors](../errors/troubleshooting.md)).

    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.
    r’   r   r#   r”   c                   sN   t  | ¡} ˆ dkrt| tƒrtjtdtƒ › d�dd� t jˆ d�}t  	| |¡S )Nr%   zªUsing `@model_validator` with mode='after' on a classmethod is deprecated. Instead, use an instance method. See the documentation at https://pydantic.dev/docs/validation/z,/concepts/validators/#model-after-validator.é   )ÚcategoryÚmessageÚ
stacklevelr¸   )
r   r•   r�   rB   ÚwarningsÚwarnr   r   ZModelValidatorDecoratorInfor–   r—   r¸   r2   r3   r™   Ü  s   
ÿú	zmodel_validator.<locals>.decN)r’   r   r#   r”   r2   )r(   r™   r2   r¸   r3   r¹   ¥  s   7ÚAnyType)r   c                   @  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:
            ```python
            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 rW   )r   ©r9   rÆ   r2   r2   r3   Ú__class_getitem__  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   ©ÚGENERATE_SCHEMA_ERRORSc                 S  rV   rW   r2   rX   r2   r2   r3   r[   /  r\   z9InstanceOf.__get_pydantic_core_schema__.<locals>.<lambda>©r]   r+   rU   )Zpython_schemaZjson_schema)Ú#pydantic._internal._generate_schemarË   r   Zis_instance_schemar   Ú
get_originr`   Zjson_or_python_schema)r9   rÉ   r"   rË   Zinstance_of_schemaÚoriginal_schemar2   r2   r3   r4     s   þ
ÿz'InstanceOf.__get_pydantic_core_schema__N)rÆ   rÄ   r#   rÄ   ©rÉ   r   r"   r   r#   r$   )	r=   r>   r?   r@   rB   rÈ   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 rW   )r   rÓ   rÇ   r2   r2   r3   rÈ   G  s   z SkipValidation.__class_getitem__rÉ   r"   r   r$   c                   sj   t  ¡ � t  dt¡ ||ƒ‰ W d   ƒ n1 sw   Y  d‡ fdd„gi}tj|tjdd„ ˆ d�d�S )NÚignoreZ pydantic_js_annotation_functionsc                   s   |ˆ ƒS rW   r2   )Z_crZ   ©rÏ   r2   r3   r[   O  r\   z=SkipValidation.__get_pydantic_core_schema__.<locals>.<lambda>c                 S  rV   rW   r2   rX   r2   r2   r3   r[   S  r\   rÌ   )ÚmetadatarU   )rÂ   Úcatch_warningsÚsimplefilterr   r   Ú
any_schemar`   )r9   rÉ   r"   rÖ   r2   rÕ   r3   r4   J  s   

þÿþz+SkipValidation.__get_pydantic_core_schema__N)rÆ   r   r#   r   rÐ   )	r=   r>   r?   r@   rÈ   rB   r4   rÑ   rÒ   r2   r2   r2   r3   rÓ   :  s    

rÓ   Ú
_FromTypeTc                   @  s$   e Zd ZdZddd	„Zddd„ZdS )Ú
ValidateAsa…  A helper class to validate a custom type from a type that is natively supported by Pydantic.

    Args:
        from_type: The type natively supported by Pydantic to use to perform validation.
        instantiation_hook: A callable taking the validated type as an argument, and returning
            the populated custom type.

    Example:
        ```python {lint="skip"}
        from typing import Annotated

        from pydantic import BaseModel, TypeAdapter, ValidateAs

        class MyCls:
            def __init__(self, a: int) -> None:
                self.a = a

            def __repr__(self) -> str:
                return f"MyCls(a={self.a})"

        class Model(BaseModel):
            a: int


        ta = TypeAdapter(
            Annotated[MyCls, ValidateAs(Model, lambda v: MyCls(a=v.a))]
        )

        print(ta.validate_python({'a': 1}))
        #> MyCls(a=1)
        ```
    Úinstantiation_hookúCallable[[_FromTypeT], Any]Ú	from_typeúTypeForm[_FromTypeT]r#   ÚNonec                C  s   || _ || _d S rW   )rÞ   rÜ   )r0   rÞ   rÜ   r2   r2   r3   Ú__init__  s   
zValidateAs.__init__rÉ   r   r"   r   r$   c                 C  sh   ddl m} || jƒ}tj| j|d�}z||ƒ}W n |y&   t ¡ }Y nw tjdd„ |d�|d< |S )Nr   rÊ   r*   c                 S  rV   rW   r2   rX   r2   r2   r3   r[   –  r\   z9ValidateAs.__get_pydantic_core_schema__.<locals>.<lambda>rÌ   rU   )rÍ   rË   rÞ   r   r/   rÜ   rÙ   r`   )r0   rÉ   r"   rË   Zfrom_type_schemar+   Z
ser_schemar2   r2   r3   r4   ƒ  s   
þÿ
ÿz'ValidateAs.__get_pydantic_core_schema__N)rÜ   rÝ   rÞ   rß   r#   rà   rÐ   )r=   r>   r?   r@   rá   r4   r2   r2   r2   r3   rÛ   ]  s    
!rÛ   )r&   r�   r‚   r�   r(   rƒ   r€   r„   rE   r   r#   r…   )r&   r�   r‚   r�   r(   r‰   r€   r„   rE   r   r#   rŠ   )
r&   r�   r‚   r�   r(   r‹   r€   r„   r#   rŠ   )r&   r�   r‚   r�   r(   r   r€   r„   rE   r   r#   rŒ   )r(   rƒ   r#   r·   )r(   rº   r#   r»   )r(   r‹   r#   r¼   )r(   r½   r#   r   )Vr@   Ú
__future__r   Z_annotationsÚdataclassesÚsysrÂ   Úcollections.abcr   Ú	functoolsr   Útypingr   r   r   r   r	   r
   r   r   Zpydantic_corer   r   Ztyping_extensionsr   r   Ú	_internalr   r   Zannotated_handlersr   Úerrorsr   Úversionr   r   r   Úversion_infor   Zinspect_validatorr,   Ú	dataclassr   rD   rS   ra   re   ro   rs   rv   r-   r.   ry   rA   rc   rd   rz   rB   Ústaticmethodr{   r|   r~   r   r‡   rœ   r�   ZValidatorFunctionWrapHandlerrŸ   r¤   r©   r¬   r®   r¯   r±   r²   ZValidationInfor³   r´   rµ   r¶   r¹   rÄ   rÅ   rÓ   rÚ   rÛ   r2   r2   r2   r3   Ú<module>   sà    (
<BcJÿþý
ÿÿþý
ÿ*þú
ú
ûúqÿþý
ÿ
J
=
