o
    Ahm                     @  s,  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rddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z; ddl<m=Z= G dd de/Z>dld$d%Z?e
dmd'd(Z@dnd1d2ZAdodpd:d;ZBdqdAdBZCdrdEdFZDdsdIdJZEh dKZFh dLZGddMdtdTdUZHdudXdYZIdddZdvd]d^ZJdwd`daZKdxdcddZLdxdedfZMdydjdkZNdS )zzmPrivate 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                   @  s   e Zd ZdZdZdS )PydanticMetadataz0Base class for annotation markers like `Strict`. N)__name__
__module____qualname____doc__	__slots__r(   r(   r(   [/var/www/html/openai_agents/venv/lib/python3.10/site-packages/pydantic/_internal/_fields.pyr'   '   s    r'   metadatar   returnr!   c                  K  s
   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)r/   r(   r(   r.   pydantic_general_metadata-   s   
	r2   type[BaseMetadata]c                  C  s"   ddl m}  G dd dt| }|S )zCDo it this way to avoid importing `annotated_types` at import time.r   r    c                   @  s   e Zd ZdZdddZdS )z7_general_metadata_cls.<locals>._PydanticGeneralMetadataz,Pydantic general metadata like `max_digits`.r/   r   c                 S  s
   || _ d S N)__dict__)selfr/   r(   r(   r.   __init__A   s   
z@_general_metadata_cls.<locals>._PydanticGeneralMetadata.__init__N)r/   r   )r)   r*   r+   r,   r7   r(   r(   r(   r.   _PydanticGeneralMetadata>   s    r8   )annotated_typesr!   r'   )r!   r8   r(   r(   r.   r1   9   s   r1   protected_namespacestuple[str | Pattern[str], ...]ann_namestrbasestuple[type[Any], ...]cls_nameNonec                 C  s<  t  }| D ]}d}t|tr||d u}n
t|tr ||}|r|D ]%}t||rIt||r8|t|di v sIt	d|dt|| d|dq$g }| D ]%}	t|	tre|	|sd|
d|	jd qN||	ss|
d	|	 d	 qNd
d| t|dkrdnd }
tjd|d|d|d|
 d	tdd qd S )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	   matchr=   
startswithhasattr
issubclassgetattr
ValueErrorappendpatternjoinlenwarningswarnUserWarning)r:   r<   r>   r@   r#   protected_namespacens_violationbvalid_namespacespnvalid_namespaces_strr(   r(   r.   _check_protected_namespacesG   sH   






$r_   Fcls	type[Any]fieldsdict[str, FieldInfo]use_inspectboolc                 C  s>   t | |d}| D ]\}}|jd u r||v r|| |_q
d S )Nrd   )r   itemsdescription)r`   rb   rd   fields_docsr<   
field_infor(   r(   r.   _update_fields_from_docstringsr   s   
rk   title_generatorCallable[[str, FieldInfo], str]
field_namerj   r"   c                 C  sB   |j d u r| ||}t|tstd|  d|j ||_ d S d S )Nzfield_title_generator  must return str, not )titlerK   r=   	TypeError	__class__)rl   rn   rj   rp   r(   r(   r.   *_apply_field_title_generator_to_field_infoy   s   



rs   alias_generator%Callable[[str], str] | AliasGeneratorc                 C  s  |j du s|j dks|jdu s|jdu s|jdu rd\}}}t| tr,| |\}}}nt| rD| |}t|tsDt	d|  d|j
 |j du sN|j dkrQd|_ |j dkret|||_t|||_||_|jdu rm||_|jdu rxt|||_|jdu rt|||_dS dS dS )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_aliasrK   r   generate_aliasescallabler=   rq   rr   r   )rt   rn   rj   rw   rx   ry   r(   r(   r.   $_apply_alias_generator_to_field_info   s4   











r|   config_wrapperr   c                 C  s@   |j p| j }|durt||| | jdurt| j|| dS dS )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_generatorrs   rt   r|   )r}   rn   rj   r~   r(   r(   r.   update_field_from_config   s   

r   >   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_maptype[BaseModel]ns_resolverNsResolver | Noner   Mapping[TypeVar, Any] | None%tuple[dict[str, FieldInfo], set[str]]c             
     sT  t  }t  | j}i }t|D ]}t|dd }r|| qtj| |d}	t| }
i }t	 }|	
 D ]S\}\}}|dkr@q4t|j||| jd t|rU|| q4t| |ttur~t fddtD s|tdr~t fd	dtD r~tt|sq4| jr|d
krtd|dt| di d}|D ];}dd t|rt|ndD }t||r||u rq||v rq||
vrqtjd| d| j d|j dtdd qtu r||
v s||vr|j |t!j"d}|sd|_#||_$nmt%|| }nft&|rt'j(rj()d| }|_(|j*d< |j+|t!j"d}|_,|s.d|_#||_$n#d|j-v rQ|. sQtjd|d|d|dt/dd  || q4zt0| | W n
 t1yb   Y nw | j2d! }||j3v rzt4d"|d#| jd$|||< |j#rt5||| q4|r|6 D ]}|j#r|7| q|j8rt9| | ||fS )%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.
    rB   N)r   model_config)r:   r<   r>   r@   c                 3  s     | ]}t  |d u V  qd S r4   )rP   .0	depr_name
BaseModel_assigned_valuer(   r.   	<genexpr>  s    z'collect_model_fields.<locals>.<genexpr>__func__c                 3  s*    | ]}t t  |d dd ju V  qd S )Nr   )rP   r   r   r   r(   r.   r   #  s
    
rootzUnexpected field with name z4; only 'root' is allowed as a field of a `RootModel`__pydantic_generic_metadata__originc                 S  s   h | ]}|j qS r(   name)r   fieldr(   r(   r.   	<setcomp>7  s    z'collect_model_fields.<locals>.<setcomp>r(   zField name "z" in "z"" shadows an attribute in parent ""   rI   _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>.`)categoryrJ   __pydantic_decorators__rC   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   r_   r:   r)   is_classvar_annotationaddr   any_deprecated_method_namesrN   _deprecated_classmethod_namesis_valid_field_name__pydantic_root_model__	NameErrorgetdataclassesis_dataclassrb   rV   rW   r+   rX   from_annotationr   CLASS	_complete_original_annotationr   rK   r   r   __get___attributes_setfrom_annotated_attribute_original_assignment_qualifiersis_requiredr   delattrAttributeErrorr5   computed_fieldsrq   r   valuesapply_typevars_mapuse_attribute_docstringsrk   )r`   r}   r   r   
FieldInfo_r>   parent_fields_lookupbasemodel_fields
type_hintsr   rb   
class_varsr<   ann_type	evaluatedgeneric_origindataclass_fieldsrj   r   
decoratorsr   r(   r   r.   collect_model_fields   s   










r   r   Mapping[TypeVar, Any]c                C  s   t  }i }|| ] | j D ]N\}}|jr|||< q|j}tj|jg|j	R  }	t
|	|}	|j }
tu r@|j|	tjd}n	|j|	|
tjd}|jdurQ|jn||_t||| |||< qW d   |S 1 sjw   Y  |S )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   pushrB   rg   r   rh   r   	eval_typer   types_namespacer   replace_typesr   r   r   r   r   r   r   )r`   r}   r   r   r   rebuilt_fieldsf_namerj   existing_descannassign	new_fieldr(   r(   r.   rebuild_model_fields  s0   


r   )r   r   type[StandardDataclass]dict[Any, Any] | Nonec             	   C  s  t  }i }|p	t }| j}t| jD ]}t|sq|| | D ]\}}	t	
|}
||
vr2q$|j\}}t	|	j||\}}t	|rGq$|	jsW|	jtju rW|	jtju rWq$t|	j|r|	jjrr|	jjdu rqtd| dddq$|j||	jtjd}|	j|_n|j||	tjd}|	|_|sd|_||_|||< t||| |jturtt| |||rt| ||j q$W d   n1 sw   Y  q|r|  D ]}|!| q|j"rt#| |t$| d d	 |S )
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__rf   )%r   r   __dataclass_fields__r   __mro__r   r   r   rg   r   r   r   try_eval_typetyper   initr   MISSINGdefault_factoryrK   init_varr   r   r   	DATACLASSr   r   r   r   r   rP   setattrr   r   r   rk   rN   )r`   r}   r   r   r   rb   r   r   r<   dataclass_field	base_annsglobalnslocalnsr   r   rj   r   r(   r(   r.   collect_dataclass_fields  sx   







9
r   type[PydanticDataclass]c                C  s   t  }i }|| N | j D ]?\}}|jr|||< q|j}tj|jg|j	R  }	t
|	|}	|j|	|jtjd}
|
jdurB|
jn||
_t|||
 |
||< qW d   |S 1 s[w   Y  |S )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   rB   rg   r   rh   r   r   r   r   r   r   r   r   r   r   r   )r`   r}   r   r   r   r   r   rj   r   r   r   r(   r(   r.   rebuild_dataclass_fields9  s4   


r   r   c                 C  s   |  d S )N_rM   r   r(   r(   r.   r   g  s   r   c                 C  s   |  do
|  d S )Nr   __r   r   r(   r(   r.   is_valid_privateattr_namek  s   r   r   3Callable[[], Any] | Callable[[dict[str, Any]], Any]'TypeIs[Callable[[dict[str, Any]], Any]]c              	   C  s\   zt | }W n ttfy   Y dS w t|j }t|dko-t|d o-|d jt	j
u S )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  r(   r(   r.   takes_validated_data_argumento  s   (r  )r/   r   r0   r!   )r0   r3   )
r:   r;   r<   r=   r>   r?   r@   r=   r0   rA   )F)r`   ra   rb   rc   rd   re   r0   rA   )rl   rm   rn   r=   rj   r"   )rt   ru   rn   r=   rj   r"   )r}   r   rn   r=   rj   r"   r0   rA   )
r`   r   r}   r   r   r   r   r   r0   r   )
r`   r   r}   r   r   r   r   r   r0   rc   )
r`   r   r}   r   r   r   r   r   r0   rc   )
r`   r   r}   r   r   r   r   r   r0   rc   )r   r=   r0   re   )r   r   r0   r   )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   r9   r!   rb   r"   mainr#   _dataclassesr$   r%   _decoratorsr&   r'   r2   r1   r_   rk   rs   r|   r   r   r   r   r   r   r   r   r   r  r(   r(   r(   r.   <module>   sf    

+


2 
H1
l
.
