
    RPf9                     j   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rddlmZ  G d d      Zer>d 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Z.dZ/dddddddde'de0de0de0de0dee0   de0deegd f   fd!Z1ed"edd fd#       Z2edddd$de0de0d%e0deegd f   fd&       Z2	 d?dddd$d"ee   de0de0d%e0ded eegd f   f   f
d'Z2d(ede0dd fd)Z3 G d* d+      Z4d,ee'ef   dee'ee   f   fd-Z5d,ee'ef   deee   eee0ef      f   fd.Z6d@d/Z7d0edd1fd2Z8d3ee   dd4fd5Z9h d6Z:d0ed7d8d9ee'   dd1fd:Z;d0ed7d8d9ee'   dd1fd;Z<d<d=dee'd f   fd>Z=y)A    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                   <    e Zd ZdZ	 	 	 	 	 d
dedededededefdZy	)	Validatorfuncpre	each_itemalwayscheck_fieldsskip_on_failurer   r   r    r!   r"   r#   c                 X    || _         || _        || _        || _        || _        || _        y Nr   )selfr   r   r    r!   r"   r#   s          V/var/www/fastapitest/venv/lib/python3.12/site-packages/pydantic/v1/class_validators.py__init__zValidator.__init__   s0     	"(.    N)FFFFF)__name__
__module____qualname__	__slots__r   boolr(    r)   r'   r   r      sW    WI
 " %// / 	/
 / / /r)   r   )	Signature)
BaseConfig)
ModelField)	ModelOrDc_FUNCS__validator_config____root_validator_config__FT)r   r    r!   r"   wholeallow_reusefieldsr   r    r!   r"   r7   r8   returnr   c                     st        d      t        d   t              rt        d      t        d D              st        d      |(t	        j
                  dt               du sJ d       | d	t        d
df f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              3   <   K   | ]  }t        |t                y wr%   )
isinstancestr).0fields     r'   	<genexpr>zvalidator.<locals>.<genexpr>N   s     <EE3'<s   zvalidator fields should be passed as separate string args. E.g. usage should be `@validator('<field_name_1>', '<field_name_2>', ...)`zdThe "whole" keyword argument is deprecated, use "each_item" (inverse meaning, default False) insteadFz0"each_item" and "whole" conflict, remove "whole"fr:   r   c                 v    t        |       }t        |t        t        |j                        f       |S )N)r   r   r    r!   r"   )_prepare_validatorsetattrVALIDATOR_CONFIG_KEYr   __func__)rB   f_clsr8   r!   r"   r    r9   r   s     r'   deczvalidator.<locals>.dec\   sB    "1k2 u~~3)TZiuv	
 r)   )r   r=   r   allwarningswarnDeprecationWarningr   )r   r    r!   r"   r7   r8   r9   rI   s   ```` `` r'   	validatorrN   4   s    & >??	F1I|	,E
 	
 <V<<Y
 	

 r	
 E!U#UU!I	
{ 
/ 
 
 Jr)   _funcc                      y r%   r/   )rO   s    r'   root_validatorrQ   k   s    r)   r   r8   r#   r#   c                      y r%   r/   rR   s      r'   rQ   rQ   p   s     r)   c          	          | r5t        |       }t        |t        t        |j                               |S dt
        ddff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#   rB   r:   r   c           	      n    t        |       }t        |t        t        |j                               |S )NrU   )rD   rE   ROOT_VALIDATOR_CONFIG_KEYr   rG   )rB   rH   r8   r   r#   s     r'   rI   zroot_validator.<locals>.dec   s5    "1k2,iU^^QTfu.v	
 r)   )rD   rE   rW   r   rG   r   )rO   r   r8   r#   rH   rI   s    ```  r'   rQ   rQ   w   sU     "5+6,iU^^QTfu.v	
 { /  Jr)   functionc           	      B   t        | t              r| n
t        |       }t               sw|sut        |j                  dd      dz   t        |j                  ddt        |j                         d      z   }|t        v rt        d| d      t        j                  |       |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`)	r=   classmethodr   getattrrG   idr4   r   add)rX   r8   rH   refs       r'   rD   rD      s    
 #8[9H{8?TE<ENNL2CDennn8MbQVQ_Q_N`Maab6cde 	
 &= >seCqrss

3Lr)   c                   <    e Zd ZddZdedeeeef      fdZddZ	y)	ValidatorGroupr:   Nc                 "    || _         dh| _        y )N*)
validatorsused_validators)r&   re   s     r'   r(   zValidatorGroup.__init__   s    $ #ur)   namec                 J   | j                   j                  |       | j                  j                  |g       }|t        k7  r|| j                  j                  dg       z  }|r=|D ci c]1  }t        |j                  ddt        |j                         d      |3 c}S y c c}w )Nrd   r*   <No __name__: id:r[   )rf   r_   re   getr   r]   r   r^   )r&   rg   re   vs       r'   get_validatorszValidatorGroup.get_validators   s      &__((r2
8$//--c266J_ijZ[GAFFJ2CBqvvJ<q0QRTUUjj ks   &6B c                      t        t        j                   fd j                  j	                          j
                  z
  D                    }|r dj                  |      }t        d| d      y )Nc              3   J   K   | ]  }d  j                   |   D          yw)c           	   3      K   | ]>  }|j                   r0t        |j                  d dt        |j                         d       @ yw)r*   ri   r[   N)r"   r]   r   r^   )r?   rk   s     r'   rA   z<ValidatorGroup.check_for_unused.<locals>.<genexpr>.<genexpr>   s>      ~~ AFFJ2CBqvvJ<q0QRs   AAN)re   )r?   rB   r&   s     r'   rA   z2ValidatorGroup.check_for_unused.<locals>.<genexpr>   s1        !__Q/  s    #z, z*Validators defined with incorrect fields: zO (use check_fields=False if you're inheriting from the model and intended this))setr   from_iterablere   keysrf   joinr   )r&   unused_validatorsfns   `  r'   check_for_unusedzValidatorGroup.check_for_unused   s}       //..043G3GG  	
 ,-B<RD Aa b  r)   )re   ValidatorListDictr:   N)r:   N)
r*   r+   r,   r(   r>   r   r   r   rl   rv   r/   r)   r'   rb   rb      s-    %3 8Di4H+I r)   rb   	namespacec                     i }| j                         D ]D  \  }}t        |t        d       }|s|\  }}|D ]!  }||v r||   j                  |       |g||<   # F |S r%   )itemsr]   rF   append)rx   re   var_namevaluevalidator_configr9   rk   r@   s           r'   extract_validatorsr      s{    -/J$??, ,%"5*>E(IFA ,J&u%,,Q/)*Ju%	,	, r)   c                    ddl m} g }g }| j                         D ]  \  }}t        |t        d       }|s ||j
                        }t        |j                  j                               }|d   dk(  rt        d| d| d      t        |      dk7  rt        d| d| d      |j                  r|j                  |j
                         |j                  |j                  |j
                  f        ||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).)inspectr   rz   r]   rW   r   list
parametersrr   r   lenr   r{   r#   )	rx   r   pre_validatorspost_validatorsrg   r}   r~   sigargss	            r'   extract_root_validatorsr      s   !(*N68O ( be07?XZ^0_,112C++-.DAw& !;D6C5 I0 1  4yA~!$I$rRUQVVq"rss##%%&6&;&;<&&(8(H(HJZJ_J_'`a!b" ?**r)   c                 b    | j                         D ]  \  }}||vrg ||<   ||xx   |z  cc<    |S r%   )rz   )base_validatorsre   r@   field_validatorss       r'   inherit_validatorsr      sK    #2#8#8#: .
" "Ju5--. r)   rN   ValidatorCallablec                 t   ddl m} t        | t        t        f      s, ||       }t        |j                  j                               }nr || j                        } || j                        j                  j                         D cg c]-  }|| j                  | j                  j                         z  vr|/ }}|j                  d      }|dk(  rt        d|  d| d      |dk(  r( t        |       t        | |t        |dd	                   S  t        |       t!        | |t        |                  S c c}w )
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   r   r&    Invalid signature for validator r   z, "self" not permitted as first argument, should be: (cls, value, values, config, field), "values", "config" and "field" are all optional.clsr   N)r   r   r=   r   r   r   r   rr   r   r   keywordspopr   r   _generic_validator_clsrp   _generic_validator_basic)rN   r   r   r   k	first_args         r'   make_generic_validatorr      s5    "i'=!9:	"CNN'')* 	' y~~.99>>@
	););)@)@)BBB 
 
 IF.ykC5 Ao p
 	
 
e	uY 6y#s4PQPR8} UVV  uY 8CT STT#
s   2D5v_funcsValidatorsListc                 D    | D cg c]  }|st        |       c}S c c}w r%   )r   )r   rB   s     r'   prep_validatorsr     s    /6<!!"1%<<<s   >   r@   configvaluesr   r0   r   c                 4    d}d|v rd}|dhz  }|j                  t              st        d  d| d      |r fdS |t               k(  r fdS |d	hk(  r fd
S |dhk(  r fdS |dhk(  r fdS |d	dhk(  r fdS |d	dhk(  r fdS |ddhk(  r fdS  fdS )NFkwargsTr   r   zb, should be: (cls, value, values, config, field), "values", "config" and "field" are all optional.c                      | ||||      S N)r   r@   r   r/   r   rk   r   r@   r   rN   s        r'   <lambda>z(_generic_validator_cls.<locals>.<lambda>.      YsAf\ajp5q r)   c                      | |      S r%   r/   r   s        r'   r   z(_generic_validator_cls.<locals>.<lambda>0  s    YsA5F r)   r   c                      | ||      S N)r   r/   r   s        r'   r   z(_generic_validator_cls.<locals>.<lambda>2      YsAf5U r)   r@   c                      | ||      S N)r@   r/   r   s        r'   r   z(_generic_validator_cls.<locals>.<lambda>4  s    YsAU5S r)   r   c                      | ||      S N)r   r/   r   s        r'   r   z(_generic_validator_cls.<locals>.<lambda>6  r   r)   c                      | |||      S N)r   r@   r/   r   s        r'   r   z(_generic_validator_cls.<locals>.<lambda>8  s    YsAf\a5b r)   c                      | |||      S N)r   r   r/   r   s        r'   r   z(_generic_validator_cls.<locals>.<lambda>:  s    YsAf]c5d r)   c                      | |||      S N)r@   r   r/   r   s        r'   r   z(_generic_validator_cls.<locals>.<lambda><  s    YsAU[a5b r)   c                      | ||||      S r   r/   r   s        r'   r   z(_generic_validator_cls.<locals>.<lambda>?  r   r)   issubset
all_kwargsr   rp   rN   r   r   
has_kwargss   `   r'   r   r      s    J4

==$.ykC5 Ad e
 	

 qq	FF	(	UU	'	SS	(	UU	(G$	$bb	(H%	%dd	'8$	$bb rqr)   c                 4    d}d|v rd}|dhz  }|j                  t              st        d  d| d      |r fdS |t               k(  r fdS |d	hk(  r fd
S |dhk(  r fdS |dhk(  r fdS |d	dhk(  r fdS |d	dhk(  r fdS |ddhk(  r fdS  fdS )NFr   Tr   r   z], should be: (value, values, config, field), "values", "config" and "field" are all optional.c                      ||||      S r   r/   r   s        r'   r   z*_generic_validator_basic.<locals>.<lambda>O      YqW\ek5l r)   c                      |      S r%   r/   r   s        r'   r   z*_generic_validator_basic.<locals>.<lambda>Q  s    Yq\ r)   r   c                      ||      S r   r/   r   s        r'   r   z*_generic_validator_basic.<locals>.<lambda>S      Yq5P r)   r@   c                      ||      S r   r/   r   s        r'   r   z*_generic_validator_basic.<locals>.<lambda>U  s    Yq5N r)   r   c                      ||      S r   r/   r   s        r'   r   z*_generic_validator_basic.<locals>.<lambda>W  r   r)   c                      |||      S r   r/   r   s        r'   r   z*_generic_validator_basic.<locals>.<lambda>Y  s    YqW\5] r)   c                      |||      S r   r/   r   s        r'   r   z*_generic_validator_basic.<locals>.<lambda>[  s    YqX^5_ r)   c                      |||      S r   r/   r   s        r'   r   z*_generic_validator_basic.<locals>.<lambda>]  s    YqV\5] r)   c                      ||||      S r   r/   r   s        r'   r   z*_generic_validator_basic.<locals>.<lambda>`  r   r)   r   r   s   `   r'   r   r   B  s    J4

==$.ykC5 A_ `
 	

 ll	AA	(	PP	'	NN	(	PP	(G$	$]]	(H%	%__	'8$	$]] mlr)   type_r3   c                     t        | j                  D cg c]  }|j                   c} }|j                         D ci c](  \  }}t	        |t
              st	        |t              r||* c}}S c c}w c c}}w r%   )r   __mro____dict__rz   hasattrrF   rW   )r   r   all_attributesr   rk   s        r'   gather_all_validatorsr   c  sm    FFGN #((*Aq1*+wq:S/T 	
1   Gs
   A/-A4r%   )r   rw   re   rw   r:   rw   )>rK   collectionsr   	functoolsr   r   r   	itertoolsr   typesr   typingr	   r
   r   r   r   r   r   r   r   r   r   r   errorsr   r   utilsr   r   r   r   r   r0   r   r1   r9   r2   r3   r>   r   r   rw   rp   r4   __annotations__rF   rW   r.   rN   rQ   rD   rb   r   r   r   r   r   r   r   r   r   r/   r)   r'   <module>r      s7      3 3   r r r r   '&/ /( !""  (9"5sDcNJX\]gXh!ikn!no+,NS$y/125C - 7 
  44	4 4 	4
 4 D>4 4 {m--.4n 
+ *:  
 
eU'+FJ{m--. 
 $(8=SXrwK 15LPko
X{m5E&EFFG0 4 DT $ D$sCx. T#tI:N5O +tCH~ +%[@QSWX]^bdo^oXpSq@q:r +2$Uk $U6I $UN=Xk2 =7G = +
rk r r3s8 rXk rDm m+ mSQTX mZm mB c;K6K1L r)   