
    hm                       d Z ddlmZ ddlZddlZddlmZ ddlm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mZmZmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2 er ddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z; ddl<m=Z=  G d de/      Z>d2d Z?e
d3d!       Z@	 	 	 	 	 	 	 	 	 	 d4d"ZAd5d6d#ZB	 	 	 	 	 	 d7d$ZC	 	 	 	 	 	 d8d%ZDd9d&ZEh d'ZFh d(ZGdd)	 	 	 	 	 	 	 	 	 d:d*ZH	 	 	 	 	 	 	 	 	 	 d;d+ZIddd,	 	 	 	 	 	 	 	 	 d<d-ZJ	 	 	 	 	 	 	 	 	 	 d=d.ZKd>d/ZLd>d0ZM	 	 	 	 d?d1ZNy)@zmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.    )annotationsN)Mapping)copy)cache)	Parameterismethoddescriptor	signature)Pattern)TYPE_CHECKINGAnyCallableTypeVar)PydanticUndefined)TypeIs)AnnotationSource)PydanticDeprecatedSince211)PydanticUserError   )AliasGenerator   )	_generics_typing_extra)ConfigWrapper)extract_docstrings_from_cls)import_cached_base_modelimport_cached_field_info)
NsResolver)Representation)can_be_positionalget_first_not_noneBaseMetadata)	FieldInfo)	BaseModel)PydanticDataclassStandardDataclass)DecoratorInfosc                      e Zd ZdZdZy)PydanticMetadataz0Base class for annotation markers like `Strict`. N)__name__
__module____qualname____doc__	__slots__r*       ?D:\jyotish\venv\Lib\site-packages\pydantic/_internal/_fields.pyr)   r)   '   s
    :Ir0   r)   c                 "     t               |       S )zCreate a new `_PydanticGeneralMetadata` class with the given metadata.

    Args:
        **metadata: The metadata to add.

    Returns:
        The new `_PydanticGeneralMetadata` class.
    )_general_metadata_cls)metadatas    r1   pydantic_general_metadatar5   -   s     # "8,,r0   c                 2    ddl m}   G d dt        |       }|S )zCDo it this way to avoid importing `annotated_types` at import time.r   r!   c                      e Zd ZdZddZy)7_general_metadata_cls.<locals>._PydanticGeneralMetadataz,Pydantic general metadata like `max_digits`.c                    || _         y N)__dict__)selfr4   s     r1   __init__z@_general_metadata_cls.<locals>._PydanticGeneralMetadata.__init__A   s	    $DMr0   N)r4   r   )r+   r,   r-   r.   r=   r*   r0   r1   _PydanticGeneralMetadatar8   >   s
    :	%r0   r>   )annotated_typesr"   r)   )r"   r>   s     r1   r3   r3   9   s     -%#3\ % $#r0   c                   t               }| D ]\  }d}t        |t              r|j                  |      d u}n!t        |t              r|j                  |      }|sN|D ]I  }t        ||      st        ||      r|t        |di       v r,t        d|dt        ||       d|d       g }| D ]k  }	t        |	t              r2|	j                  |      r%|j                  d|	j                  d       E|j                  |	      rW|j                  d	|	 d	       m d
dj                  |       t        |      dk(  rdnd }
t        j                  d|d|d|d|
 d	t         d       _ y )NF__pydantic_fields__Field z conflicts with member z of protected namespace .zre.compile()'(z, r   z,)z in z$ conflicts with protected namespace zX.

You may be able to solve this by setting the 'protected_namespaces' configuration to    
stacklevel)r   
isinstancer
   matchstr
startswithhasattr
issubclassgetattr
ValueErrorappendpatternjoinlenwarningswarnUserWarning)protected_namespacesann_namebasescls_namer$   protected_namespacens_violationbvalid_namespacespnvalid_namespaces_strs              r1   _check_protected_namespacesrc   G   s    )*I3)73.44X>dJL+S1#../BCL1h'&q)4WQPegiEj9j($XL0GPQS[H\G]67J6MQP   /1 .B!"g.!xx1,33k"**q4QR'2226,33at1I> / *+4995E+F*GPSTdPeijPjpsGt'u$XLXL8\]p\s tl mA  lB  BCD 	7  4r0   c                    t        | |      }|j                         D ]!  \  }}|j                  ||v s||   |_        # y )Nuse_inspect)r   itemsdescription)clsfieldsrf   fields_docsrZ   
field_infos         r1   _update_fields_from_docstringsrm   r   sC    -c{KK &*!!)h+.E%0%:J" !/r0   c                    |j                   < | ||      }t        |t              st        d|  d|j                         ||_         y y )Nzfield_title_generator  must return str, not )titlerJ   rL   	TypeError	__class__)title_generator
field_namerl   rp   s       r1   *_apply_field_title_generator_to_field_inforu   y   sV    
 
J7%%4_4EE[\a\k\k[lmnn 
  r0   c                   |j                   4|j                   dk  s%|j                  |j                  |j                  d\  }}}t	        | t
              r| j                  |      \  }}}n>t        |       r3 | |      }t	        |t              st        d|  d|j                         |j                   |j                   dk  rd|_         |j                   dk(  r)t        ||      |_        t        ||      |_        ||_        |j                  ||_        |j                  t        ||      |_        |j                  t        ||      |_        yyy)av  Apply an alias generator to aliases on a `FieldInfo` instance if appropriate.

    Args:
        alias_generator: A callable that takes a string and returns a string, or an `AliasGenerator` instance.
        field_name: The name of the field from which to generate the alias.
        field_info: The `FieldInfo` instance to which the alias generator is (maybe) applied.
    Nr   )NNNzalias_generator ro   )alias_priorityaliasvalidation_aliasserialization_aliasrJ   r   generate_aliasescallablerL   rq   rr   r    )alias_generatorrt   rl   rx   ry   rz   s         r1   $_apply_alias_generator_to_field_infor~      sh    	!!)$$)#&&.))17G4!4o~6;J;[;[\f;g8E#%8o&#J/EeS)"2?2CCYZ_ZiZiYj kll
 $$,
0I0IQ0N()J% $$)-?@SUZ-[J**<=Mu*UJ'$J #$J))1-?@SUZ-[J*&&.*<=Mu*UJ' /9 2r0   c                    |j                   xs | j                   }|t        |||       | j                  t        | j                  ||       yy)ap  Update the `FieldInfo` instance from the configuration set on the model it belongs to.

    This will apply the title and alias generators from the configuration.

    Args:
        config_wrapper: The configuration from the model.
        field_name: The field name the `FieldInfo` instance is attached to.
        field_info: The `FieldInfo` instance to update.
    N)field_title_generatorru   r}   r~   )config_wrapperrt   rl   r   s       r1   update_field_from_configr      sS     '<<d@d@d(23H*V`a%%1,^-K-KZYcd 2r0   >   r   dictjson_iter_calculate_keys_copy_and_set_values>
   schemafrom_ormvalidate	construct	parse_obj	parse_raw
_get_value
parse_fileschema_jsonupdate_forward_refs)typevars_mapc                  t               }t               | j                  }i }t        |      D ]#  }t	        |dd      x}s|j                  |       % t        j                  | |      }	t        j                  |       }
i }t               }|	j                         D ];  \  }\  }}|dk(  rt        |j                  ||| j                         t        j                  |      r|j                  |       Zt	        | |t               t         urDt#        fdt$        D              s%t'        d      rt#        fdt(        D              rt         t+        |      s| j,                  r|d	k7  rt/        d
|d      t	        | di       j1                  d      }|D ]  }t3        j4                  |      rt3        j6                  |      ndD ch c]  }|j8                   }}t'        ||      sS||u rX||v r]||
vrbt;        j<                  d| d| j>                   d|j>                   dt@        d        t         u rK||
v s||vr4|jC                  |tD        jF                        }|sd|_$        ||_%        n tM        ||         }ntO        |      rGtQ        jR                        r2jR                  jU                  d|       }|_)        |jV                  d<   |jY                  |tD        jF                        }|_-        |sd|_$        ||_%        nWd|j\                  v rI|j_                         s9t;        j<                  d|d|d|dt`        d       |j                  |       	 tc        | |       | jf                  d   }||jh                  v rtk        d|d | j                  d!      |||<   |jH                  s/tm        |||       > |r3|jo                         D ]   }|jH                  s|jq                  |       " |jr                  rtu        | |       ||fS c c}w # td        $ r Y w xY w)"a*  Collect the fields and class variables names of a nascent Pydantic model.

    The fields collection process is *lenient*, meaning it won't error if string annotations
    fail to evaluate. If this happens, the original annotation (and assigned value, if any)
    is stored on the created `FieldInfo` instance.

    The `rebuild_model_fields()` should be called at a later point (e.g. when rebuilding the model),
    and will make use of these stored attributes.

    Args:
        cls: BaseModel or dataclass.
        config_wrapper: The config wrapper instance.
        ns_resolver: Namespace resolver to use when getting model annotations.
        typevars_map: A dictionary mapping type variables to their concrete types.

    Returns:
        A two-tuple containing model fields and class variables names.

    Raises:
        NameError:
            - If there is a conflict between a field name and protected namespaces.
            - If there is a field other than `root` in `RootModel`.
            - If a field shadows an attribute in the parent model.
    rA   N)ns_resolvermodel_config)rY   rZ   r[   r\   c              3  <   K   | ]  }t        |d       u   y wr:   )rP   .0	depr_name
BaseModel_assigned_values     r1   	<genexpr>z'collect_model_fields.<locals>.<genexpr>  s"     qXp9
It4FXps   __func__c              3  f   K   | ](  }t        t        |d       dd       j                  u  * y w)Nr   )rP   r   r   s     r1   r   z'collect_model_fields.<locals>.<genexpr>#  s7      %B	 GJ	4@*dSWeWnWnn%Bs   .1rootzUnexpected field with name z4; only 'root' is allowed as a field of a `RootModel`__pydantic_generic_metadata__originr*   zField name "z" in "z"" shadows an attribute in parent ""   rH   _sourceFdefaultfinalzAnnotation z= is marked as final and has a default value. Pydantic treats zz as a class variable, but it will be considered as a normal field in V3 to be aligned with dataclasses. If you still want zV to be considered as a class variable, annotate it as: `ClassVar[<type>] = <default>.`)categoryrI   __pydantic_decorators__rB   z
 of class zf overrides symbol of same name in a parent class. This override with a computed_field is incompatible.);r   r   	__bases__reversedrP   updater   get_model_type_hintssafe_get_annotationssetrg   rc   rY   r+   is_classvar_annotationaddr   any_deprecated_method_namesrN   _deprecated_classmethod_namesis_valid_field_name__pydantic_root_model__	NameErrorgetdataclassesis_dataclassrj   namerV   rW   r-   rX   from_annotationr   CLASS	_complete_original_annotationr   rJ   r   r   __get___attributes_setfrom_annotated_attribute_original_assignment_qualifiersis_requiredr   delattrAttributeErrorr;   computed_fieldsrq   r   valuesapply_typevars_mapuse_attribute_docstringsrm   )ri   r   r   r   
FieldInfo_r[   parent_fields_lookupbasemodel_fields
type_hintsr   rj   
class_varsrZ   ann_type	evaluatedgeneric_originfielddataclass_fieldsrl   r   
decoratorsr   r   s                         @@r1   collect_model_fieldsr      st   > *+J)+JMME13"4)>EE<E ''5   33C[QJ  44S9K#%F5J+5+;+;+=''8Y~% #!/!D!D\\		
 //9NN8$ h0AB!22qXpqq 
3 %B  /N"8,&&8v+=-h\9mn  !&ErJNNxXDEPE]E]^bEc););D)Aik)k )ku

)k    tX&>)// ;."8*F33C3C2D E))*!- 	% 2 ..;&(:N*N (77JZJ`J`7a
 +0J( 7?J3 ""6x"@A
 .*5:L^McMc:d )0088sC)0&<C..y9#<<X~_o_u_u<vJ /=J+',
$2:
/J222:;Q;Q;S!(-jksjv w""*  .DE 8  x(
X& &)\\2K%L
z111Js||.> ?G G  &x$^XzJU ,>X ]]_E((6 % ..&sF3:M \ " s   P.5P33	P?>P?c                  t               }i }|j                  |       5  | j                  j                         D ]  \  }}|j                  r|||<   |j
                  }t        j                  |j                  g|j                   }	t        j                  |	|      }	|j                  x}
t        u r"|j                  |	t        j                         }n"|j#                  |	|
t        j                         }|j
                  |j
                  n||_        t%        |||       |||<    	 ddd       |S # 1 sw Y   |S xY w)a  Rebuild the (already present) model fields by trying to reevaluate annotations.

    This function should be called whenever a model with incomplete fields is encountered.

    Raises:
        NameError: If one of the annotations failed to evaluate.

    Note:
        This function *doesn't* mutate the model fields in place, as it can be called during
        schema generation, where you don't want to mutate other model's fields.
    r   N)r   pushrA   rg   r   rh   r   	eval_typer   types_namespacer   replace_typesr   r   r   r   r   r   r   )ri   r   r   r   r   rebuilt_fieldsf_namerl   existing_descannassign	new_fields               r1   rebuild_model_fieldsr     s2   $ *+J+-N			#	"%"9"9"?"?"AFJ##)3v& * 6 6#--33 00  --c<@(===FBSS * : :3HXH^H^ : _I * C CCYiYoYo C pIAJAVAVAb	(=(=hu	%(K)2v&% #B 
* + 
* s   D
D33D=)r   r   c          
     l   t               }i }|xs
 t               }| j                  }t        | j                        D ]  }t        j                  |      s|j                  |      5  |j                         D ]  \  }}	t        j                  |      }
||
vr!|j                  \  }}t        j                  |	j                  ||      \  }}t        j                  |      rj|	j                  s9|	j                   t
        j"                  u r|	j$                  t
        j"                  u rt'        |	j                   |      r|	j                   j(                  r+|	j                   j                  du rt+        d| dd      |j-                  ||	j                   t.        j0                        }|	j                   |_        n)|j-                  ||	t.        j0                        }|	|_        |sd|_        ||_        |||<   t9        |||       |j                   t:        ust'        t=        | ||      |      st?        | ||j                           	 ddd        |r&|jA                         D ]  }|jC                  |        |jD                  rtG        | |tI        | d       	       |S # 1 sw Y   wxY w)
a|  Collect the fields of a dataclass.

    Args:
        cls: dataclass.
        config_wrapper: The config wrapper instance.
        ns_resolver: Namespace resolver to use when getting dataclass annotations.
            Defaults to an empty instance.
        typevars_map: A dictionary mapping type variables to their concrete types.

    Returns:
        The dataclass fields.
    FzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)coder   N__is_pydantic_dataclass__re   )%r   r   __dataclass_fields__r   __mro__r   r   r   rg   r   r   r   try_eval_typetyper   initr   MISSINGdefault_factoryrJ   init_varr   r   r   	DATACLASSr   r   r   r   r   rP   setattrr   r   r   rm   rN   )ri   r   r   r   r   rj   r   r   rZ   dataclass_field	base_annsglobalnslocalnsr   r   rl   r   s                    r1   collect_dataclass_fieldsr     s   & *+J#%F-K//
 %''-d#-=-C-C-E)/)>>tD	9, $/$?$?!'&3&A&A/BVBVX`bi&j#) 77A (,,'//;3F3FF'77;;N;NN o55zB&..77*22775@"3"28*  =A  !B%A#  !!+!D!D /"9"9CSC]C] "E "J 7F6M6MJ3!+!D!D /;K;U;U "E "J 7FJ3 +0J(6>J3#-x (:N%%->>:C:6
D C:+=+=>m .F $#	 &z ]]_E $$\2	 % ..& $C)DEE	
 MS $#s   'F2J)J)4J))J3	c               (   t               }i }|j                  |       5  | j                  j                         D ]  \  }}|j                  r|||<   |j
                  }t        j                  |j                  g|j                   }	t        j                  |	|      }	|j                  |	|j                  t        j                        }
|
j
                  |
j
                  n||
_        t!        |||
       |
||<    	 ddd       |S # 1 sw Y   |S xY w)a  Rebuild the (already present) dataclass fields by trying to reevaluate annotations.

    This function should be called whenever a dataclass with incomplete fields is encountered.

    Raises:
        NameError: If one of the annotations failed to evaluate.

    Note:
        This function *doesn't* mutate the dataclass fields in place, as it can be called during
        schema generation, where you don't want to mutate other dataclass's fields.
    r   N)r   r   rA   rg   r   rh   r   r   r   r   r   r   r   r   r   r   r   )ri   r   r   r   r   r   r   rl   r   r   r   s              r1   rebuild_dataclass_fieldsr   9  s   $ *+J+-N			#	"%"9"9"?"?"AFJ##)3v& * 6 6#--33 00  --c<@&??33,66 @ 	 BKAVAVAb	(=(=hu	%(K)2v&' #B 
, - 
, s   CDDc                &    | j                  d       S )N_rM   r   s    r1   r   r   g  s    s###r0   c                L    | j                  d      xr | j                  d       S )Nr   __r   r   s    r1   is_valid_privateattr_namer   k  s"    ??3=(=$==r0   c                   	 t        |       }t        |j                  j                               }t        |      dk(  xr/ t        |d         xr |d   j                  t        j                  u S # t        t        f$ r Y yw xY w)zMWhether the provided default factory callable has a validated data parameter.Fr   r   )r	   rQ   rq   list
parametersr   rU   r   r   r   empty)r   sigr  s      r1   takes_validated_data_argumentr  o  s    ( cnn++-.Jz?aq$5jm$DqTUI^I^bkbqbqIqq 	"  s   A/ /B B)r4   r   returnr"   )r  ztype[BaseMetadata])
rY   ztuple[str | Pattern[str], ...]rZ   rL   r[   ztuple[type[Any], ...]r\   rL   r  None)F)ri   z	type[Any]rj   dict[str, FieldInfo]rf   boolr  r  )rs   zCallable[[str, FieldInfo], str]rt   rL   rl   r#   )r}   z%Callable[[str], str] | AliasGeneratorrt   rL   rl   r#   )r   r   rt   rL   rl   r#   r  r  )
ri   type[BaseModel]r   r   r   NsResolver | Noner   zMapping[TypeVar, Any] | Noner  z%tuple[dict[str, FieldInfo], set[str]])
ri   r
  r   r   r   r   r   Mapping[TypeVar, Any]r  r  )
ri   ztype[StandardDataclass]r   r   r   r  r   zdict[Any, Any] | Noner  r  )
ri   ztype[PydanticDataclass]r   r   r   r   r   r  r  r  )r   rL   r  r	  )r   z3Callable[[], Any] | Callable[[dict[str, Any]], Any]r  z'TypeIs[Callable[[dict[str, Any]], Any]])Or.   
__future__r   _annotationsr   rV   collections.abcr   r   	functoolsr   inspectr   r   r	   rer
   typingr   r   r   r   pydantic_corer   typing_extensionsr   typing_inspection.introspectionr   pydanticr   pydantic.errorsr   aliasesr    r   r   _configr   _docs_extractionr   _import_utilsr   r   _namespace_utilsr   _reprr   _utilsr   r    r?   r"   rj   r#   mainr$   _dataclassesr%   r&   _decoratorsr'   r)   r5   r3   rc   rm   ru   r~   r   r   r   r   r   r   r   r   r   r  r*   r0   r1   <module>r$     s)   s 2   #   < <  8 8 + $ < / - $ & " 9 M ( ! 9," B+~ 	- 
$ 
$(8(( !( 	(
 
(V;
!4
!
! 
!/V:/VHK/VYb/Vde" h ! & 26D	D!D #D
 /D +DN*	* "* 	*
 (* *b &**.i	 i "i #	i
 (i iX+	 + "+ 	+
 (+ +\$>rHr,rr0   