U
    nËj(  ã                   @  s<  U d Z ddlmZ ddlmZ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mZmZmZ dd	lmZmZ dd
lmZ ddlmZ dZe
�r~G dd„ deƒZG dd„ deƒZG dd„ deƒZ G dd„ deƒZ!G dd„ deƒZ"G dd„ deƒZ#eeee e!e"ej$ej%ej&ej'f	 Z(ee#ej)f Z*ee+eeef e,eef ee f Z-de.d< ede(e-ƒZ/edej)e#e-ƒZ0neZ1eddd�d d d dd d!œd"d"d#d#d#d$d#d%d&œd'd(„ƒZ2ed)d*œd+d#d,d-œd.d/„ƒZ3ed)d*œd+d#d,d0œd1d/„ƒZ3ed)d*œd2d+d#d,d3œd4d/„ƒZ3ed5dd�d d d d6œd#d#d#d7d3œd8d/„ƒZ3dS )9zCOld `@validator` and `@root_validator` function validators from V1.é    )Úannotations)ÚpartialÚpartialmethod)ÚFunctionType)ÚTYPE_CHECKINGÚAnyÚCallableÚTypeVarÚUnionÚoverload)Úwarn)ÚLiteralÚProtocolÚ	TypeAliasÚ
deprecatedé   )Ú_decoratorsÚ_decorators_v1)ÚPydanticUserError)ÚPydanticDeprecatedSince20zQ`allow_reuse` is deprecated and will be ignored; it should no longer be necessaryc                   @  s   e Zd Zddddœdd„ZdS )Ú_OnlyValueValidatorClsMethodr   )Ú!_OnlyValueValidatorClsMethod__clsÚ#_OnlyValueValidatorClsMethod__valueÚreturnc                 C  s   d S ©N© )Úselfr   r   r   r   úH/tmp/pip-unpacked-wheel-zvl9l234/pydantic/deprecated/class_validators.pyÚ__call__   ó    z%_OnlyValueValidatorClsMethod.__call__N©Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   r      s   r   c                   @  s    e Zd Zdddddœdd„ZdS )Ú_V1ValidatorWithValuesClsMethodr   údict[str, Any])Ú$_V1ValidatorWithValuesClsMethod__clsÚ&_V1ValidatorWithValuesClsMethod__valueÚvaluesr   c                 C  s   d S r   r   )r   r&   r'   r(   r   r   r   r      r   z(_V1ValidatorWithValuesClsMethod.__call__Nr    r   r   r   r   r$      s   r$   c                   @  s    e Zd Zdddddœdd„ZdS )Ú%_V1ValidatorWithValuesKwOnlyClsMethodr   r%   )Ú*_V1ValidatorWithValuesKwOnlyClsMethod__clsÚ,_V1ValidatorWithValuesKwOnlyClsMethod__valuer(   r   c                C  s   d S r   r   )r   r*   r+   r(   r   r   r   r      r   z._V1ValidatorWithValuesKwOnlyClsMethod.__call__Nr    r   r   r   r   r)      s   r)   c                   @  s   e Zd Zddddœdd„ZdS )Ú_V1ValidatorWithKwargsClsMethodr   )Ú$_V1ValidatorWithKwargsClsMethod__clsÚkwargsr   c                 K  s   d S r   r   )r   r-   r.   r   r   r   r      r   z(_V1ValidatorWithKwargsClsMethod.__call__Nr    r   r   r   r   r,      s   r,   c                   @  s    e Zd Zdddddœdd„ZdS )Ú(_V1ValidatorWithValuesAndKwargsClsMethodr   r%   )Ú-_V1ValidatorWithValuesAndKwargsClsMethod__clsr(   r.   r   c                 K  s   d S r   r   )r   r0   r(   r.   r   r   r   r   "   r   z1_V1ValidatorWithValuesAndKwargsClsMethod.__call__Nr    r   r   r   r   r/   !   s   r/   c                   @  s   e Zd Zddddœdd„ZdS )Ú_V1RootValidatorClsMethodr   z"_decorators_v1.RootValidatorValues)Ú_V1RootValidatorClsMethod__clsÚ!_V1RootValidatorClsMethod__valuesr   c                 C  s   d S r   r   )r   r2   r3   r   r   r   r   %   s    z"_V1RootValidatorClsMethod.__call__Nr    r   r   r   r   r1   $   s   r1   r   Ú_PartialClsOrStaticMethodÚ_V1ValidatorTypeÚ_V1RootValidatorFunctionTypeú©Pydantic V1 style `@validator` validators are deprecated. You should migrate to Pydantic V2 style `@field_validator` validators, see the migration guide for more detailsN)ÚcategoryF)ÚpreÚ	each_itemÚalwaysÚcheck_fieldsÚallow_reuseÚstrÚboolzbool | Nonez.Callable[[_V1ValidatorType], _V1ValidatorType])Ú__fieldÚfieldsr9   r:   r;   r<   r=   r   c                  s”   t dtdd� |dkr t ttƒ | fˆ˜‰tˆd tƒrFtddd�‚ntd	d
„ ˆD ƒƒsdtddd�‚|dkrpdnd‰dddœ‡ ‡‡‡‡fdd„}|S )aä  Decorate methods on the class indicating that they should be used to validate fields.

    Args:
        __field (str): The first field the 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 (str): Additional field(s) the validator should be called on.
        pre (bool, optional): Whether this validator should be called before the standard
            validators (else after). Defaults to False.
        each_item (bool, optional): For complex objects (sets, lists etc.) whether to validate
            individual elements rather than the whole object. Defaults to False.
        always (bool, optional): Whether this method and other validators should be called even if
            the value is missing. Defaults to False.
        check_fields (bool | None, optional): Whether to check that the fields actually exist on the model.
            Defaults to None.
        allow_reuse (bool, optional): Whether to track and raise an error if another validator refers to
            the decorated function. Defaults to False.

    Returns:
        Callable: A decorator that can be used to decorate a
            function to be used as a validator.
    r7   r   ©Ú
stacklevelTr   z`@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 r   )Ú
isinstancer>   )Ú.0Úfieldr   r   r   Ú	<genexpr>�   s     zvalidator.<locals>.<genexpr>zˆ`@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ÚbeforeÚafterr   z(_decorators.PydanticDescriptorProxy[Any]©Úfr   c                   sJ   t  | ¡rtddd�‚t  | ¡} tj}t jˆˆˆˆ ˆd�}t j| ||d�S )Nz2`@validator` cannot be applied to instance methodszvalidator-instance-methodrD   )rA   Úmoder:   r;   r<   ©Zshim)r   Úis_instance_method_from_sigr   Ú%ensure_classmethod_based_on_signaturer   Zmake_generic_v1_field_validatorZValidatorDecoratorInfoÚPydanticDescriptorProxy)rM   ÚwrapZvalidator_wrapper_info©r;   r<   r:   rA   rN   r   r   ÚdecŠ   s    
 ÿ
ûzvalidator.<locals>.dec)r   ÚDeprecationWarningÚ_ALLOW_REUSE_WARNING_MESSAGErF   r   r   Úall)r@   r9   r:   r;   r<   r=   rA   rU   r   rT   r   Ú	validatorL   s*    $û

ýýrY   .)r=   zLiteral[True]zFCallable[[_V1RootValidatorFunctionType], _V1RootValidatorFunctionType])Úskip_on_failurer=   r   c                 C  s   d S r   r   )rZ   r=   r   r   r   Úroot_validatorž   s    
r[   )r9   r=   r   c                 C  s   d S r   r   )r9   r=   r   r   r   r[   «   s    
zLiteral[False])r9   rZ   r=   r   c                 C  s   d S r   r   ©r9   rZ   r=   r   r   r   r[   ¸   s    ú®Pydantic V1 style `@root_validator` validators are deprecated. You should migrate to Pydantic V2 style `@model_validator` validators, see the migration guide for more detailsr\   r   c                   s‚   t dtdd� |rtƒ |Ž S |dkr.t ttƒ | dkr:dnd‰ | dkrZ|dk	rZtdd	d
�‚ttj| d�‰dddœ‡ ‡fdd„}|S )aõ  Decorate methods on a model indicating that they should be used to validate (and perhaps
    modify) data either before or after standard model parsing/validation is performed.

    Args:
        pre (bool, optional): Whether this validator should be called before the standard
            validators (else after). Defaults to False.
        skip_on_failure (bool, optional): Whether to stop validation and return as soon as a
            failure is encountered. Defaults to False.
        allow_reuse (bool, optional): Whether to track and raise an error if another validator
            refers to the decorated function. Defaults to False.

    Returns:
        Any: A decorator that can be used to decorate a function to be used as a root_validator.
    r]   r   rB   TrJ   rK   Fz¼If you use `@root_validator` with pre=False (the default) you MUST specify `skip_on_failure=True`. Note that `@root_validator` is deprecated and should be replaced with `@model_validator`.zroot-validator-pre-skiprD   )r9   zHCallable[..., Any] | classmethod[Any, Any, Any] | staticmethod[Any, Any]r   rL   c                   s8   t  | ¡rtdƒ‚t  | ¡}t jˆ d�}t j||ˆd�S )Nz7`@root_validator` cannot be applied to instance methods)rN   rO   )r   rP   Ú	TypeErrorrQ   ZRootValidatorDecoratorInforR   )rM   ÚresZdec_info©rN   rS   r   r   rU   ø   s
    

zroot_validator.<locals>.dec)r   rV   r[   rW   r   r   r   Zmake_v1_generic_root_validator)r9   rZ   r=   Z__argsrU   r   r`   r   r[   Æ   s$    û

ý)4Ú__doc__Ú
__future__r   Z_annotationsÚ	functoolsr   r   Útypesr   Útypingr   r   r   r	   r
   r   Úwarningsr   Ztyping_extensionsr   r   r   r   Ú	_internalr   r   Úerrorsr   r   rW   r   r$   r)   r,   r/   r1   ZV1ValidatorWithValuesZV1ValidatorWithValuesKwOnlyZV1ValidatorWithKwargsZV1ValidatorWithValuesAndKwargsZV1ValidatorZV1RootValidatorFunctionZV1RootValidatorÚclassmethodÚstaticmethodr4   Ú__annotations__r5   r6   rV   rY   r[   r   r   r   r   Ú<module>   sŒ    øÿÿÿ,ü	ü	ù"Lûûúüü