o
    ZhP9                     @   s.  U d dl 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
 d dlmZmZmZmZmZ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 erYd d
lmZ G dd dZ erd dl!m"Z" d dl#m$Z$ d dl%m&Z& d dl'm(Z( eee( eee)ef e&ee$ gef Z*ee* Z+ee)ee  f Z,e- Z.ee) e/d< dZ0dZ1dddddddde)de2de2de2de2dee2 de2deegdf fd d!Z3ed"eddfd#d$Z4edddd%de2de2d&e2deegdf fd'd$Z4	dKdddd%d"ee de2de2d&e2dedeegdf f f
d(d$Z4d)ede2ddfd*d+Z5G d,d- d-Z6d.ee)ef dee)ee  f fd/d0Z7d.ee)ef deee eee2ef  f fd1d2Z8dLd6d7Z9d!edd8fd9d:Z:d;ee dd<fd=d>Z;h d?Z<d!ed@dAdBee) dd8fdCdDZ=d!ed@dAdBee) dd8fdEdFZ>dGdHdee)df fdIdJZ?dS )M    N)ChainMap)partialpartialmethodwraps)chain)FunctionType)TYPE_CHECKINGAnyCallableDictIterableListOptionalSetTupleTypeUnionoverload)ConfigError)AnyCallable)ROOT_KEY
in_ipython)AnyClassMethodc                   @   s>   e Zd ZdZ					ddedededededefd	d
ZdS )	Validatorfuncpre	each_itemalwayscheck_fieldsskip_on_failureFr   r   r   r   r   r    c                 C   s(   || _ || _|| _|| _|| _|| _d S Nr   )selfr   r   r   r   r   r     r#   S/var/www/html/lang_env/lib/python3.10/site-packages/pydantic/v1/class_validators.py__init__   s   	
zValidator.__init__N)FFFFF)__name__
__module____qualname__	__slots__r   boolr%   r#   r#   r#   r$   r      s(    r   )	Signature)
BaseConfig)
ModelField)	ModelOrDc_FUNCSZ__validator_config__Z__root_validator_config__FT)r   r   r   r   wholeallow_reusefieldsr   r   r   r   r0   r1   returnr   c                    s   st dtd trt dtdd D st d|dur3tdt d	u s0J d
| dtddf fdd}|S )a  
    Decorate methods on the class indicating that they should be used to validate fields
    :param fields: which field(s) the method should be called on
    :param pre: whether or not this validator should be called before the standard validators (else after)
    :param each_item: for complex objects (sets, lists etc.) whether to validate individual elements rather than the
      whole object
    :param always: whether this method and other validators should be called even if the value is missing
    :param check_fields: whether to check that the fields actually exist on the model
    :param allow_reuse: whether to track and raise an error if another validator refers to the decorated function
    z"validator with no fields specifiedr   z}validators should be used with fields and keyword arguments, not bare. E.g. usage should be `@validator('<field_name>', ...)`c                 s   s    | ]}t |tV  qd S r!   )
isinstancestr).0fieldr#   r#   r$   	<genexpr>N   s    zvalidator.<locals>.<genexpr>zvalidator fields should be passed as separate string args. E.g. usage should be `@validator('<field_name_1>', '<field_name_2>', ...)`NzdThe "whole" keyword argument is deprecated, use "each_item" (inverse meaning, default False) insteadFz0"each_item" and "whole" conflict, remove "whole"fr3   r   c                    s.   t |  }t|tt|jdf |S )N)r   r   r   r   r   )_prepare_validatorsetattrVALIDATOR_CONFIG_KEYr   __func__r9   f_clsr1   r   r   r   r2   r   r#   r$   dec\   s   
zvalidator.<locals>.dec)r   r4   r   allwarningswarnDeprecationWarningr   )r   r   r   r   r0   r1   r2   rA   r#   r@   r$   	validator4   s&    rF   _funcc                 C      d S r!   r#   )rG   r#   r#   r$   root_validatork   s   rI   r   r1   r    r    c                 C   rH   r!   r#   rJ   r#   r#   r$   rI   p   s   c                   sH   | rt |  }t|tt|jd |S dtddf fdd}|S )z
    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.
    r   r   r    r9   r3   r   c                    s&   t |  }t|tt|jd |S )NrK   )r:   r;   ROOT_VALIDATOR_CONFIG_KEYr   r=   r>   r1   r   r    r#   r$   rA      s
   
zroot_validator.<locals>.dec)r:   r;   rL   r   r=   r   )rG   r   r1   r    r?   rA   r#   rM   r$   rI   w   s   
functionc                 C   st   t | tr| nt| }t s8|s8t|jddd t|jddt|j d }|tv r3td| dt| |S )	z
    Avoid validators with duplicated names since without this, validators can be overwritten silently
    which generally isn't the intended behaviour, don't run in ipython (see #312) or if allow_reuse is False.
    r'   z<No __module__>.r(   z<No __qualname__: id:>zduplicate validator function "z."; if this is intended, set `allow_reuse=True`)	r4   classmethodr   getattrr=   idr/   r   add)rN   r1   r?   refr#   r#   r$   r:      s   

r:   c                   @   s>   e Zd ZdddZdedeeeef  fdd	Zdd
dZ	dS )ValidatorGroup
validatorsValidatorListDictr3   Nc                 C   s   || _ dh| _d S )N*)rW   used_validators)r"   rW   r#   r#   r$   r%      s   zValidatorGroup.__init__namec                 C   sJ   | j | | j|g }|tkr|| jdg 7 }|r#dd |D S d S )NrY   c                 S   s*   i | ]}t |jd dt|j d|qS )r&   <No __name__: id:rP   )rR   r   rS   r6   vr#   r#   r$   
<dictcomp>   s   * z1ValidatorGroup.get_validators.<locals>.<dictcomp>)rZ   rT   rW   getr   )r"   r[   rW   r#   r#   r$   get_validators   s   zValidatorGroup.get_validatorsc                    sJ   t t fdd j  j D }|r#d|}td| dd S )Nc                 3   s$    | ]}d d  j | D V  qdS )c                 s   s2    | ]}|j rt|jd dt|j dV  qdS )r&   r\   rP   N)r   rR   r   rS   r]   r#   r#   r$   r8      s    
z<ValidatorGroup.check_for_unused.<locals>.<genexpr>.<genexpr>N)rW   r6   r9   r"   r#   r$   r8      s    
z2ValidatorGroup.check_for_unused.<locals>.<genexpr>z, z*Validators defined with incorrect fields: zO (use check_fields=False if you're inheriting from the model and intended this))setr   from_iterablerW   keysrZ   joinr   )r"   Zunused_validatorsfnr#   rc   r$   check_for_unused   s   


zValidatorGroup.check_for_unused)rW   rX   r3   N)r3   N)
r&   r'   r(   r%   r5   r   r   r   ra   ri   r#   r#   r#   r$   rV      s    

rV   	namespacec                 C   s^   i }|   D ]&\}}t|td }|r,|\}}|D ]}||v r&|| | q|g||< qq|S r!   )itemsrR   r<   append)rj   rW   var_namevaluevalidator_configr2   r^   r7   r#   r#   r$   extract_validators   s   rp   c           	      C   s   ddl m} g }g }|  D ]M\}}t|td }|r[||j}t|j }|d dkr7t	d| d| dt
|dkrHt	d| d| d|jrR||j q||j|jf q||fS )	Nr   	signaturer"   z%Invalid signature for root validator : zC, "self" not permitted as first argument, should be: (cls, values).   z, should be: (cls, values).)inspectrr   rk   rR   rL   r   list
parametersrf   r   lenr   rl   r    )	rj   rr   Zpre_validatorsZpost_validatorsr[   rn   ro   sigargsr#   r#   r$   extract_root_validators   s&   
r{   base_validatorsrX   rW   c                 C   s6   |   D ]\}}||vrg ||< ||  |7  < q|S r!   )rk   )r|   rW   r7   Zfield_validatorsr#   r#   r$   inherit_validators   s
   r}   ValidatorCallablec                    s   ddl m} t ttfs| }t|j }n| j} fdd| jj D }|	d}|dkrAt
d  d| d|d	krUt t |t|d
d S t t |t|S )a  
    Make a generic function which calls a validator with the right arguments.

    Unfortunately other approaches (eg. return a partial of a function that builds the arguments) is slow,
    hence this laborious way of doing things.

    It's done like this so validators don't all need **kwargs in their signature, eg. any combination of
    the arguments "values", "fields" and/or "config" are permitted.
    r   rq   c                    s$   g | ]}| j  j B vr|qS r#   )rz   keywordsrf   )r6   krF   r#   r$   
<listcomp>  s
    z*make_generic_validator.<locals>.<listcomp>r"    Invalid signature for validator rs   z, "self" not permitted as first argument, should be: (cls, value, values, config, field), "values", "config" and "field" are all optional.cls   N)ru   rr   r4   r   r   rv   rw   rf   r   popr   r   _generic_validator_clsrd   _generic_validator_basic)rF   rr   ry   rz   Z	first_argr#   r   r$   make_generic_validator   s    



 r   v_funcsValidatorsListc                 C   s   dd | D S )Nc                 S   s   g | ]}|rt |qS r#   )r   rb   r#   r#   r$   r     s    z#prep_validators.<locals>.<listcomp>r#   )r   r#   r#   r$   prep_validators  s   r   >   configvaluesr7   ry   r+   rz   c                       d}d|v rd}|dh8 }| tstd  d| d|r% fddS |t kr0 fd	dS |d
hkr; fddS |dhkrF fddS |dhkrQ fddS |d
dhkr] fddS |d
dhkri fddS |ddhkru fddS  fddS )NFkwargsTr   rs   zb, should be: (cls, value, values, config, field), "values", "config" and "field" are all optional.c                        | ||||dS N)r   r7   r   r#   r   r^   r   r7   r   r   r#   r$   <lambda>.      z(_generic_validator_cls.<locals>.<lambda>c                    s
    | |S r!   r#   r   r   r#   r$   r   0  s   
 r   c                    s    | ||dS N)r   r#   r   r   r#   r$   r   2      r7   c                    s    | ||dS N)r7   r#   r   r   r#   r$   r   4  r   r   c                    s    | ||dS N)r   r#   r   r   r#   r$   r   6  r   c                    s    | |||dS N)r   r7   r#   r   r   r#   r$   r   8      c                    s    | |||dS N)r   r   r#   r   r   r#   r$   r   :  r   c                    s    | |||dS N)r7   r   r#   r   r   r#   r$   r   <  r   c                    r   r   r#   r   r   r#   r$   r   ?  r   issubset
all_kwargsr   rd   rF   ry   rz   Z
has_kwargsr#   r   r$   r      s2   





r   c                    r   )NFr   Tr   rs   z], should be: (value, values, config, field), "values", "config" and "field" are all optional.c                        ||||dS r   r#   r   r   r#   r$   r   O  r   z*_generic_validator_basic.<locals>.<lambda>c                    s    |S r!   r#   r   r   r#   r$   r   Q  s    r   c                    s    ||dS r   r#   r   r   r#   r$   r   S      r7   c                    s    ||dS r   r#   r   r   r#   r$   r   U  r   r   c                    s    ||dS r   r#   r   r   r#   r$   r   W  r   c                    s    |||dS r   r#   r   r   r#   r$   r   Y  r   c                    s    |||dS r   r#   r   r   r#   r$   r   [  r   c                    s    |||dS r   r#   r   r   r#   r$   r   ]  r   c                    r   r   r#   r   r   r#   r$   r   `  r   r   r   r#   r   r$   r   B  s2   





r   type_r.   c                 C   s&   t dd | jD  }dd | D S )Nc                 S   s   g | ]}|j qS r#   )__dict__)r6   r   r#   r#   r$   r   d  r   z)gather_all_validators.<locals>.<listcomp>c                 S   s*   i | ]\}}t |tst |tr||qS r#   )hasattrr<   rL   )r6   r   r^   r#   r#   r$   r_   e  s    z)gather_all_validators.<locals>.<dictcomp>)r   __mro__rk   )r   Zall_attributesr#   r#   r$   gather_all_validatorsc  s   r   r!   )r|   rX   rW   rX   r3   rX   )@rC   collectionsr   	functoolsr   r   r   	itertoolsr   typesr   typingr   r	   r
   r   r   r   r   r   r   r   r   r   Zpydantic.v1.errorsr   Zpydantic.v1.typingr   Zpydantic.v1.utilsr   r   r   r   ru   r+   Zpydantic.v1.configr,   Zpydantic.v1.fieldsr-   Zpydantic.v1.typesr.   r5   r~   r   rX   rd   r/   __annotations__r<   rL   r*   rF   rI   r:   rV   rp   r{   r}   r   r   r   r   r   r   r#   r#   r#   r$   <module>   s   
 8&
7
&"2
'"!