HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //usr/local/lib/python3.10/dist-packages/pydantic/__pycache__/functional_validators.cpython-310.pyc
o

|��g�r�@s:UdZddlmZddlZddlZddlmZddlm	Z	ddl
mZmZm
Z
mZmZmZmZddlmZmZddlmZdd	lmZmZmZmZd
dlmZmZmZd
dlm Z d
d
l!m"Z"ej#dkrkddlm$Z$nddl
m$Z$ej%Z&ej'dbddiej(��Gdd�d��Z)ej'dbddiej(��Gdd�d��Z*ej'dbddiej(��Gdd�d��Z+ej'dbddiej(��Gdd�d��Z,e�rGdd�de$�Z-Gdd�de$�Z.Gdd�de$�Z/Gd d!�d!e$�Z0ee.ej1e-ej2fZ3ee0ej4e/ej5fZ6ee7eeefe8eefeefZ9d"e:d#<ed$ee3e9fd%�Z;ed&ee6e9fd%�Z<ed'Z=d"e:d(<ed)d)d*�dcd6d7��Z>ed)d)d*�ddd:d7��Z>ed)d)d;�ded=d7��Z>d>ded?�dfdAd7�Z>edB�Z?edCddD�Z@GdEdF�dFejAe$e@�ZBGdGdH�dHe$e?�ZCGdIdJ�dJe$e?�ZDGdKdL�dLe$�ZEGdMdN�dNe$�ZFGdOdP�dPe$�ZGGdQdR�dRe$�ZHe
e?ge?fZI	e
e?ejJge?fZK	eeDe?eCe?fZLeeGeHeEeFfZMeeKe?eIe?fZNedgdTdU��ZOedhdXdU��ZOedidZdU��ZOdjd\dU�ZOed]�ZPe�r�eePd)fZQnej'dbiej(��Gd^d_�d_��ZQe�reePd)fZRdSej'dbiej(��Gd`da�da��ZRdS)kzBThis module contains related classes and functions for validation.�)�annotationsN)�
partialmethod)�FunctionType)�
TYPE_CHECKING�Any�Callable�TypeVar�Union�cast�overload)�PydanticUndefined�core_schema)r
)�	Annotated�Literal�Self�	TypeAlias�)�_decorators�	_generics�_internal_dataclass)�GetCoreSchemaHandler)�PydanticUserError)��)�Protocol�frozenTc@s2eZdZUdZded<dd
d�Zeddd��ZdS)�AfterValidatora9Usage docs: https://docs.pydantic.dev/2.10/concepts/validators/#field-validators

    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_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�handlerr�return�core_schema.CoreSchemacCsT||�}t|jd�}|rttj|j�}tj|||jd�Sttj|j�}tj||d�S)N�after)�schema�
field_name)r$)	�_inspect_validatorrr
r
�WithInfoValidatorFunction�"with_info_after_validator_functionr%�NoInfoValidatorFunction� no_info_after_validator_function)�selfrr r$�info_argr�r-�I/usr/local/lib/python3.10/dist-packages/pydantic/functional_validators.py�__get_pydantic_core_schema__Hsz+AfterValidator.__get_pydantic_core_schema__�	decorator�>_decorators.Decorator[_decorators.FieldValidatorDecoratorInfo]rcCs||jd�S)N�rr2��clsr0r-r-r.�_from_decoratorRszAfterValidator._from_decoratorN�rrr rr!r"�r0r1r!r)�__name__�
__module__�__qualname__�__doc__�__annotations__r/�classmethodr5r-r-r-r.rs
)

rc@�>eZdZUdZded<eZded<ddd�Zeddd��Z	dS)�BeforeValidatoraeUsage docs: https://docs.pydantic.dev/2.10/concepts/validators/#field-validators

    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 of the function. This is only used to generate the appropriate
            JSON Schema (in validation mode).

    Example:
        ```python
        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
        ```
    rrr�json_schema_input_typerr rr!r"cC�r||�}|jturdn|�|j�}t|jd�}|r*ttj|j�}tj|||j	|d�Sttj
|j�}tj|||d�S)N�before�r$r%�json_schema_input_schema�r$rD)r@r�generate_schemar&rr
r
r'�#with_info_before_validator_functionr%r)�!no_info_before_validator_function�r+rr r$�input_schemar,rr-r-r.r/{s$
�
���z,BeforeValidator.__get_pydantic_core_schema__r0r1rcC�||j|jjd�S�N)rr@�r�infor@r3r-r-r.r5���zBeforeValidator._from_decoratorNr6r7�
r8r9r:r;r<rr@r/r=r5r-r-r-r.r?Ws

r?c@r>)�PlainValidatoraUsage docs: https://docs.pydantic.dev/2.10/concepts/validators/#field-validators

    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 of the function. This is only used to generate the appropriate
            JSON Schema (in validation mode). If not provided, will default to `Any`.

    Example:
        ```python
        from typing import Union

        from typing_extensions import Annotated

        from pydantic import BaseModel, PlainValidator

        MyInt = Annotated[
            int,
            PlainValidator(
                lambda v: int(v) + 1, json_schema_input_type=Union[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`.
    rrrr@rr rr!r"c		Cs�ddlm}z||�}|�dtjdd�||�|�d��}Wn|y(d}Ynw|�|j�}t|jd�}|rHt	tj
|j�}tj||j||d�St	tj
|j�}tj|||d	�S)
Nr��PydanticSchemaGenerationError�
serializationcS�||�S�Nr-��v�hr-r-r.�<lambda>��z=PlainValidator.__get_pydantic_core_schema__.<locals>.<lambda>)�functionr$�
return_schema�plain)r%rTrD)rTrD)�pydanticrS�getr
�#wrap_serializer_function_ser_schemarFr@r&rr
r'�"with_info_plain_validator_functionr%r)� no_info_plain_validator_function)	r+rr rSr$rTrJr,rr-r-r.r/�s<�����z+PlainValidator.__get_pydantic_core_schema__r0r1rcCrKrLrMr3r-r-r.r5�rOzPlainValidator._from_decoratorNr6r7)
r8r9r:r;r<rr@r/r=r5r-r-r-r.rQ�s
+
*rQc@r>)�
WrapValidatora�Usage docs: https://docs.pydantic.dev/2.10/concepts/validators/#field-validators

    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 of the function. This is only used to generate the appropriate
            JSON Schema (in validation mode).

    ```python
    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.WithInfoWrapValidatorFunctionrrr@rr rr!r"cCrA)N�wraprCrE)r@rrFr&rr
r
�WithInfoWrapValidatorFunction�!with_info_wrap_validator_functionr%�NoInfoWrapValidatorFunction�no_info_wrap_validator_functionrIr-r-r.r/'s(
�
���z*WrapValidator.__get_pydantic_core_schema__r0r1rcCrKrLrMr3r-r-r.r5@rOzWrapValidator._from_decoratorNr6r7rPr-r-r-r.rd�s
&
rdc@seZdZddd�ZdS)	�_OnlyValueValidatorClsMethodr4r�valuer!cC�dSrVr-�r+r4rkr-r-r.�__call__K�z%_OnlyValueValidatorClsMethod.__call__N�r4rrkrr!r�r8r9r:rnr-r-r-r.rjJ�rjc@�eZdZd
dd�Zd	S)�_V2ValidatorClsMethodr4rrkrN�_core_schema.ValidationInfor!cCrlrVr-�r+r4rkrNr-r-r.rnNroz_V2ValidatorClsMethod.__call__N�r4rrkrrNrur!rrqr-r-r-r.rtMrrrtc@rs)� _OnlyValueWrapValidatorClsMethodr4rrkr �)_core_schema.ValidatorFunctionWrapHandlerr!cCrlrVr-�r+r4rkr r-r-r.rnQroz)_OnlyValueWrapValidatorClsMethod.__call__N)r4rrkrr ryr!rrqr-r-r-r.rxPrrrxc@seZdZdd	d
�ZdS)
�_V2WrapValidatorClsMethodr4rrkr ryrNrur!cCrlrVr-�r+r4rkr rNr-r-r.rnT�z"_V2WrapValidatorClsMethod.__call__N)
r4rrkrr ryrNrur!rrqr-r-r-r.r{Srrr{r�_PartialClsOrStaticMethod�"_V2BeforeAfterOrPlainValidatorType)�bound�_V2WrapValidatorType)rBr#rer^�FieldValidatorModes.)�check_fieldsr@�field�str�fields�mode�Literal['wrap']r��bool | Noner@rr!�6Callable[[_V2WrapValidatorType], _V2WrapValidatorType]cGrlrVr-�r�r�r�r@r�r-r-r.�field_validatorv�r��Literal['before', 'plain']�RCallable[[_V2BeforeAfterOrPlainValidatorType], _V2BeforeAfterOrPlainValidatorType]cGrlrVr-r�r-r-r.r��r�)r�r��Literal['after']cGrlrVr-)r�r�r�r�r-r-r.r��r}r#)r�r�r@�Callable[[Any], Any]cs�t|t�rtddd���dvr�turtd���dd���tur&�dkr&t�|g��R�tdd	��D��s;td
dd��d����fdd�}|S)a6Usage docs: https://docs.pydantic.dev/2.10/concepts/validators/#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).

    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.
        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'`.

    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>', ...)`zvalidator-no-fields��code)rBr^rez;`json_schema_input_type` can't be used when mode is set to zvalidator-input-typer^css�|]}t|t�VqdSrV)�
isinstancer�)�.0r�r-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>', ...)`zvalidator-invalid-fields�f�HCallable[..., Any] | staticmethod[Any, Any] | classmethod[Any, Any, Any]r!�(_decorators.PydanticDescriptorProxy[Any]cs>t�|�rtddd��t�|�}tj����d�}t�||�S)Nz8`@field_validator` cannot be applied to instance methodszvalidator-instance-methodr�)r�r�r�r@)r�is_instance_method_from_sigr�%ensure_classmethod_based_on_signature�FieldValidatorDecoratorInfo�PydanticDescriptorProxy�r��dec_info�r�r�r@r�r-r.�dec�s
�
�zfield_validator.<locals>.decN)r�r�r!r�)r�rrrr�all)r�r�r�r@r�r�r-r�r.r��s(
C����
_ModelType�_ModelTypeCo)�	covariantc@seZdZdZ	ddd	d
�ZdS)
�ModelWrapValidatorHandlerz]`@model_validator` decorated function handler argument type. This is used when `mode='wrap'`.Nrkr�outer_location�str | int | Noner!r�cCrlrVr-)r+rkr�r-r-r.rn�z"ModelWrapValidatorHandler.__call__rV)rkrr�r�r!r��r8r9r:r;rnr-r-r-r.r�s�r�c@seZdZdZd
d
d�ZdS)�ModelWrapValidatorWithoutInfoz�A `@model_validator` decorated function signature.
    This is used when `mode='wrap'` and the function does not have info argument.
    r4�type[_ModelType]rkrr �%ModelWrapValidatorHandler[_ModelType]r!r�cCrlrVr-rzr-r-r.rn�	z&ModelWrapValidatorWithoutInfo.__call__N)r4r�rkrr r�r!r�r�r-r-r-r.r��r�c@seZdZdZddd
�ZdS)�ModelWrapValidatorzSA `@model_validator` decorated function signature. This is used when `mode='wrap'`.r4r�rkrr r�rNrur!r�cCrlrVr-r|r-r-r.rn(s
zModelWrapValidator.__call__N)
r4r�rkrr r�rNrur!r�r�r-r-r-r.r�%�r�c@seZdZdZddd�ZdS)	�#FreeModelBeforeValidatorWithoutInfo��A `@model_validator` decorated function signature.
    This is used when `mode='before'` and the function does not have info argument.
    rkrr!cCrlrVr-)r+rkr-r-r.rn:r}z,FreeModelBeforeValidatorWithoutInfo.__call__N)rkrr!rr�r-r-r-r.r�5r�r�c@seZdZdZd	dd�ZdS)
�ModelBeforeValidatorWithoutInfor�r4rrkr!cCrlrVr-rmr-r-r.rnIr�z(ModelBeforeValidatorWithoutInfo.__call__Nrpr�r-r-r-r.r�Dr�r�c@seZdZdZd
dd�Zd	S)�FreeModelBeforeValidator�UA `@model_validator` decorated function signature. This is used when `mode='before'`.rkrrNrur!cCrlrVr-)r+rkrNr-r-r.rnWr�z!FreeModelBeforeValidator.__call__N)rkrrNrur!rr�r-r-r-r.r�Tr�r�c@seZdZdZddd	�Zd
S)�ModelBeforeValidatorr�r4rrkrNrur!cCrlrVr-rvr-r-r.rner�zModelBeforeValidator.__call__Nrwr�r-r-r-r.r�br�r��|Callable[[_AnyModelWrapValidator[_ModelType]], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]cCrlrVr-�r�r-r-r.�model_validator�r�r��Literal['before']�rCallable[[_AnyModelBeforeValidator], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]cCrlrVr-r�r-r-r.r��r��}Callable[[_AnyModelAfterValidator[_ModelType]], _decorators.PydanticDescriptorProxy[_decorators.ModelValidatorDecoratorInfo]]cCrlrVr-r�r-r-r.r��r��"Literal['wrap', 'before', 'after']csd�fdd�}|S)	a'Usage docs: https://docs.pydantic.dev/2.10/concepts/validators/#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).

    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�rr!r�cs"t�|�}tj�d�}t�||�S)Nr�)rr��ModelValidatorDecoratorInfor�r�r�r-r.r��s
zmodel_validator.<locals>.decN)r�rr!r�r-)r�r�r-r�r.r��s0�AnyTypec@s2eZdZdZeddd��Zeddd
��ZejZdS)�
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!cCst||�fSrV)r�r4r�r-r-r.�__class_getitem__�szInstanceOf.__class_getitem__�sourcerr rr"cCshddlm}t�t�|�p|�}z||�}Wn|y!|YSwtjdd�|d�|d<tj||d�S)NrrRcSrUrVr-rWr-r-r.rZr[z9InstanceOf.__get_pydantic_core_schema__.<locals>.<lambda>�r\r$rT)�
python_schema�json_schema)r_rSr
�is_instance_schemar�
get_originra�json_or_python_schema)r4r�r rS�instance_of_schema�original_schemar-r-r.r/s�
�z'InstanceOf.__get_pydantic_core_schema__N)r�r�r!r��r�rr rr!r")	r8r9r:r;r=r�r/�object�__hash__r-r-r-r.r��s 
r�c@s.eZdZdZddd�Zeddd��ZejZd
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�rr!cCst|t�fSrV)rr�r�r-r-r.r�+sz SkipValidation.__class_getitem__r�r rr"cs6||��d�fdd�gi}tj|tjdd��d�d�S)N� pydantic_js_annotation_functionscs|��SrVr-)�_crY�r�r-r.rZ1r[z=SkipValidation.__get_pydantic_core_schema__.<locals>.<lambda>cSrUrVr-rWr-r-r.rZ5r[r�)�metadatarT)r
�
any_schemara)r4r�r r�r-r�r.r/.s��z+SkipValidation.__get_pydantic_core_schema__N)r�rr!rr�)	r8r9r:r;r�r=r/r�r�r-r-r-r.r�s


r�r-)r�r�r�r�r�r�r�r�r@rr!r�)r�r�r�r�r�r�r�r�r@rr!r�)
r�r�r�r�r�r�r�r�r!r�)r�r�r�r�r�r�r�r�r@rr!r�)r�r�r!r�)r�r�r!r�)r�r�r!r�)r�r�r!r)Sr;�
__future__r�_annotations�dataclasses�sys�	functoolsr�typesr�typingrrrrr	r
r�
pydantic_corerr
�_core_schema�typing_extensionsrrrr�	_internalrrr�annotated_handlersr�errorsr�version_infor�inspect_validatorr&�	dataclass�
slots_truerr?rQrdrjrtrxr{r'r)�_V2Validatorrfrh�_V2WrapValidatorr=�staticmethodr~r<rr�r�r�r�r��ValidatorFunctionWrapHandlerr�r�r�r�r�r�r��ModelAfterValidatorWithoutInfo�ValidationInfo�ModelAfterValidator�_AnyModelWrapValidator�_AnyModelBeforeValidator�_AnyModelAfterValidatorr�r�r�r�r-r-r-r.�<module>s�$
;BaK
����,
��
�
�
�n
�
9<