
    .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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l/m0Z0m1Z1 er ddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z: ddl;m<Z<  G d de.      Z=d1dZ>e	d2d        Z?	 	 	 	 	 	 	 	 	 	 d3d!Z@d4d5d"ZA	 	 	 	 	 	 d6d#ZB	 	 	 	 	 	 d7d$ZCd8d%ZDh d&ZEh d'ZFdd(	 	 	 	 	 	 	 	 	 d9d)ZG	 	 	 	 	 	 	 	 	 	 d:d*ZHddd+	 	 	 	 	 	 	 	 	 d;d,ZI	 	 	 	 	 	 	 	 	 	 d<d-ZJd=d.ZKd=d/ZL	 	 	 	 d>d0ZMy)?zmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.    )annotationsN)Mapping)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)       X/var/www/html/ai-service/venv/lib/python3.12/site-packages/pydantic/_internal/_fields.pyr(   r(   &   s
    :Ir/   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    r0   pydantic_general_metadatar4   ,   s     # "8,,r/   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__)selfr3   s     r0   __init__z@_general_metadata_cls.<locals>._PydanticGeneralMetadata.__init__@   s	    $DMr/   N)r3   r   )r*   r+   r,   r-   r<   r)   r/   r0   _PydanticGeneralMetadatar7   =   s
    :	%r/   r=   )annotated_typesr!   r(   )r!   r=   s     r0   r2   r2   8   s     -%#3\ % $#r/   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              r0   _check_protected_namespacesrb   F   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 r/   c                    t        | |      }|j                         D ]!  \  }}|j                  ||v s||   |_        # y )Nuse_inspect)r   itemsdescription)clsfieldsre   fields_docsrY   
field_infos         r0   _update_fields_from_docstringsrl   q   sH    -c{KK & ;*!!)h+.E%0%:J";r/   c                    |j                   < | ||      }t        |t              st        d|  d|j                         ||_         y y )Nzfield_title_generator  must return str, not )titlerI   rK   	TypeError	__class__)title_generator
field_namerk   ro   s       r0   *_apply_field_title_generator_to_field_infort   x   sV    
 
J7%%4_4EE[\a\k\k[lmnn 
  r/   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 rn   )alias_priorityaliasvalidation_aliasserialization_aliasrI   r   generate_aliasescallablerK   rp   rq   r   )alias_generatorrs   rk   rw   rx   ry   s         r0   $_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 2r/   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_generatorrt   r|   r}   )config_wrapperrs   rk   r   s       r0   update_field_from_configr      sS     '<<d@d@d(23H*V`a%%1,^-K-KZYcd 2r/   >   copy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 rP||
v s||vr4|jC                  |tD        jF                        }|sd|_$        ||_%        n||   jM                         }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4tm        |||       C |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.
    r@   N)ns_resolvermodel_config)rX   rY   rZ   r[   c              3  <   K   | ]  }t        |d       u   y wr9   )rO   .0	depr_name
BaseModel_assigned_values     r0   	<genexpr>z'collect_model_fields.<locals>.<genexpr>  s     q9
It4Fqs   __func__c              3  f   K   | ](  }t        t        |d       dd       j                  u  * y w)Nr   )rO   r   r   s     r0   r   z'collect_model_fields.<locals>.<genexpr>"  s7      ! GJ	4@*dSWeWnWnns   .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 ""   rG   _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>.`)categoryrH   __pydantic_decorators__rA   z
 of class zf overrides symbol of same name in a parent class. This override with a computed_field is incompatible.);r   r   	__bases__reversedrO   updater   get_model_type_hintssafe_get_annotationssetrf   rb   rX   r*   is_classvar_annotationaddr   any_deprecated_method_namesrM   _deprecated_classmethod_namesis_valid_field_name__pydantic_root_model__	NameErrorgetdataclassesis_dataclassri   namerU   rV   r,   rW   from_annotationr   CLASS	_complete_original_annotation_copyrI   r   r   __get___attributes_setfrom_annotated_attribute_original_assignment_qualifiersis_requiredr   delattrAttributeErrorr:   computed_fieldsrp   r   valuesapply_typevars_mapuse_attribute_docstringsrl   )rh   r   r   r   
FieldInfo_rZ   parent_fields_lookupbasemodel_fields
type_hintsr   ri   
class_varsrY   ann_type	evaluatedgeneric_originfielddataclass_fieldsrk   r   
decoratorsr   r   s                         @@r0   collect_model_fieldsr      s   > *+J)+JMME13 6"4)>EE<E ''56 33C[QJ  44S9K#%F5J+5+;+;+= JK''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 $

    tX&>)// ;."8*F33C3C2D E))*!- 	%	2 ..;&(:N*N (77JZJ`J`7a
 +0J( 7?J3 2(;AAC
 .*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JKX ]]_ 	7E((6	7 ..&sF3:M \ " s   P3:P88	QQ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   pushr@   rf   r   rg   r   	eval_typer   types_namespacer   replace_typesr   r   r   r   r   r   r   )rh   r   r   r   r   rebuilt_fieldsf_namerk   existing_descannassign	new_fields               r0   rebuild_model_fieldsr     s;   $ *+J+-N			#	 3"%"9"9"?"?"A 	3FJ##)3v& * 6 6#--33 00  --c<@(===FBSS * : :3HXH^H^ : _I * C CCYiYoYo C pIAJAVAVAb	(=(=hu	%(K)2v&%	33* +3* 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__rd   )%r   r   __dataclass_fields__r   __mro__r   r   r   rf   r   r   r   try_eval_typetyper   initr   MISSINGdefault_factoryrI   init_varr   r   r   	DATACLASSr   r   r   r   r   rO   setattrr   r   r   rl   rM   )rh   r   r   r   r   ri   r   r   rY   dataclass_field	base_annsglobalnslocalnsr   r   rk   r   s                    r0   collect_dataclass_fieldsr     s   & *+J#%F-K//
 % ;?''-d# 7	?-=-C-C-E 6?)/)>>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6?7	? 7	?	;?z ]]_ 	3E $$\2		3 ..& $C)DEE	
 MS7	? 7	?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   r@   rf   r   rg   r   r   r   r   r   r   r   r   r   r   r   )rh   r   r   r   r   r   r   rk   r   r   r   s              r0   rebuild_dataclass_fieldsr   8  s   $ *+J+-N			#	 3"%"9"9"?"?"A 	3FJ##)3v& * 6 6#--33 00  --c<@&??33,66 @ 	 BKAVAVAb	(=(=hu	%(K)2v&'	33, -3, s   CDDc                &    | j                  d       S )N_rL   r   s    r0   r   r   f  s    s###r/   c                L    | j                  d      xr | j                  d       S )Nr   __r   r   s    r0   is_valid_privateattr_namer   j  s"    ??3=(=$==r/   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   rP   rp   list
parametersr   rT   r   r   r   empty)r   sigr  s      r0   takes_validated_data_argumentr  n  s    ( cnn++-.Jz?aq$5jm$DqTUI^I^bkbqbqIqq 	"  s   A/ /B B)r3   r   returnr!   )r  ztype[BaseMetadata])
rX   ztuple[str | Pattern[str], ...]rY   rK   rZ   ztuple[type[Any], ...]r[   rK   r  None)F)rh   z	type[Any]ri   dict[str, FieldInfo]re   boolr  r  )rr   zCallable[[str, FieldInfo], str]rs   rK   rk   r"   )r|   z%Callable[[str], str] | AliasGeneratorrs   rK   rk   r"   )r   r   rs   rK   rk   r"   r  r  )
rh   type[BaseModel]r   r   r   NsResolver | Noner   zMapping[TypeVar, Any] | Noner  z%tuple[dict[str, FieldInfo], set[str]])
rh   r  r   r   r   r   r   Mapping[TypeVar, Any]r  r	  )
rh   ztype[StandardDataclass]r   r   r   r  r   zdict[Any, Any] | Noner  r	  )
rh   ztype[PydanticDataclass]r   r   r   r   r   r  r  r	  )r   rK   r  r
  )r   z3Callable[[], Any] | Callable[[dict[str, Any]], Any]r  z'TypeIs[Callable[[dict[str, Any]], Any]])Nr-   
__future__r   _annotationsr   rU   collections.abcr   	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!   ri   r"   mainr#   _dataclassesr$   r%   _decoratorsr&   r(   r4   r2   rb   rl   rt   r}   r   r   r   r   r   r   r   r   r   r  r)   r/   r0   <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r/   