a
    hZ                     @  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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/m0Z0 ddl1m2Z2 erjddl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z; ddl<m=Z= G dd de0Z>d d!d"d#d$Z?e
d%d&d'd(Z@dWd*d+d,d-d.d/d0ZAdd1d2d3d4d5d6d7d8d9ZBd*d:d-d;d<d=ZCd2d>d?d+d@dAdBZDddddCdDd4dEdFd+dGdHdIZEdJd3d>d?d+d7dKdLZFd:d,dMdNdOZGd:d,dMdPdQZHdRdSdTdUdVZIdS )XzmPrivate 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
get_origin)typing_objects)AnnotationSource)PydanticDeprecatedSince211)PydanticUserError   )	_generics_typing_extra)ConfigWrapper)extract_docstrings_from_cls)import_cached_base_modelimport_cached_field_info)
NsResolver)Representation)can_be_positional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(   V/var/www/html/assistant/venv/lib/python3.9/site-packages/pydantic/_internal/_fields.pyr'   '   s   r'   r   r    )metadatareturnc                  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    	r3   ztype[BaseMetadata])r0   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dZdS )z7_general_metadata_cls.<locals>._PydanticGeneralMetadataz,Pydantic general metadata like `max_digits`.r   r2   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,   r6   r(   r(   r(   r.   _PydanticGeneralMetadata>   s   r7   )annotated_typesr    r'   )r    r7   r(   r(   r.   r1   9   s    r1   Fz	type[Any]zdict[str, FieldInfo]boolNone)clsfieldsuse_inspectr0   c                 C  s>   t | |d}| D ]$\}}|jd u r||v r|| |_qd S )Nr=   )r   itemsdescription)r;   r<   r=   Zfields_docsann_name
field_infor(   r(   r.   _update_fields_from_docstringsG   s    rC   )typevars_mapztype[BaseModel]r   zNsResolver | NonezMapping[TypeVar, Any] | Nonez%tuple[dict[str, FieldInfo], set[str]])r;   config_wrapperns_resolverrD   r0   c                C  s4  t  }t }| j}i }t|D ]}t|dd }	r||	 qtj| |d}
| j	di }i }t
 }|
 D ]\}\}}|dkrql|jD ]}d}t|tr||du}nt|tr||}|r|D ]J}t||rt||r|t|di v std| dt|| d	| d
qd}|jD ]J}t|trR||sh|d|j df7 }n||s ||f7 }q td| d| j d| d| d	t qt|r|| qlt| |t}t|sql| jr|dkrtd|dt| di 	d}|D ]}dd t |rt!|ndD }t||r||u r@q||v rNq||vr\qtd| d| j" d|j" dt q|tu r||v s||vr|j#|t$j%d}|sd|_&||_'nt(|| }nt)|| t||rt*|j+r|j+,d| |_+|s t||r |- n|}|j.||t$j%d}||_/|sPd|_&||_'nFd|j0v r|1 stjd|d |d!|d"t2d#d$ || qlzt3| | W n t4y   Y n0 | jd% }||j5v rt6d&|d'| jd(|||< ql|r|7 D ]}|j&r |8| q |j9r,t:| | ||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.
    __pydantic_fields__N)rF   __annotations__Zmodel_configFzField "z" conflicts with member z of protected namespace "z".r(   zre.compile()z" in z( has conflict with protected namespace "z_".

You may be able to resolve this warning by setting `model_config['protected_namespaces'] = z`.rootzUnexpected field with name z4; only 'root' is allowed as a field of a `RootModel`Z__pydantic_generic_metadata__originc                 S  s   h | ]
}|j qS r(   name).0fieldr(   r(   r.   	<setcomp>   s   z'collect_model_fields.<locals>.<setcomp>zField name "z" in "z"" shadows an attribute in parent ""_source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>.`   )category
stacklevelZ__pydantic_decorators__zField z
 of class zf overrides symbol of same name in a parent class. This override with a computed_field is incompatible.);r   r   	__bases__reversedgetattrupdater   Zget_model_type_hintsr4   getsetr?   Zprotected_namespaces
isinstancer	   matchstr
startswithhasattr
issubclass	NameErrorpatternwarningswarnr)   UserWarningis_classvar_annotationaddr   is_valid_field_nameZ__pydantic_root_model__dataclassesis_dataclassr<   r+   from_annotationr   CLASS	_complete_original_annotationr   #_warn_on_nested_alias_in_annotationr   default__get__Z_copyfrom_annotated_attribute_original_assignmentZ_qualifiersZis_requiredr   delattrAttributeErrorZcomputed_fields	TypeErrorvaluesapply_typevars_mapuse_attribute_docstringsrC   )r;   rE   rF   rD   r#   
FieldInfo_basesZparent_fields_lookupbaseZmodel_fieldsZ
type_hintsr   r<   Z
class_varsrA   ann_type	evaluatedZprotected_namespaceZns_violationbZvalid_namespacesZpnZassigned_valueZgeneric_origindataclass_fieldsrB   Zoriginal_assignmentZ
decoratorsrO   r(   r(   r.   collect_model_fieldsN   s    
















r   r`   )r   rA   r0   c                 C  sr   t  }t| dd }|rn|D ]R}tt|rt|D ]4}t||r6|jd ur6t	
d| dt   d S q6qd S )N__args__z `alias` specification on field "z5" must be set on outermost annotation to take effect.)r   rZ   r   Zis_annotatedr   r   get_argsr^   aliasrf   rg   rh   )r   rA   r"   argsZanno_argZanno_type_argr(   r(   r.   rr     s    
rr   r   zMapping[TypeVar, Any])r;   rF   rD   r0   c                C  s   t  }i }||  | j D ]\}}|jr8|||< 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r|
jn||
_|
||< q W d   n1 s0    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.
    rR   N)r   pushrG   r?   rp   r@   r   	eval_typerq   types_namespacer   replace_typesrv   r   rn   r   ro   ru   )r;   rF   rD   r}   rebuilt_fieldsf_namerB   existing_descannZassign	new_fieldr(   r(   r.   rebuild_model_fields-  s&    
(r   )rF   rD   rE   ztype[StandardDataclass]zdict[Any, Any] | NonezConfigWrapper | None)r;   rF   rD   rE   r0   c             	   C  s  t  }i }|pt }| j}t| jD ]b}t|s6q$||4 | D ]\}}	||j	
di vrjqL|j\}
}t|	j|
|\}}t|rqL|	js|	jtju r|	jtju rqLt|	j|r
|	jjr|	jjdu rLtd| dddqL|j||	jtjd}|	j|_n|j||	tjd}|	|_|s4d|_||_|||< |jturLtt| |||rLt| ||j qLW d   q$1 s~0    Y  q$|r|  D ]}|!| q|dur|j"rt#| |t$| d	 d
 |S )a|  Collect the fields of a dataclass.

    Args:
        cls: dataclass.
        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.
        config_wrapper: The config wrapper instance.

    Returns:
        The dataclass fields.
    rH   FzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)coderR   NZ__is_pydantic_dataclass__r>   )%r   r   Z__dataclass_fields__rY   __mro__rl   rm   r   r?   r4   r\   r   r   Ztry_eval_typetyperi   initrs   MISSINGdefault_factoryr^   Zinit_varr   ru   r   	DATACLASSrv   rp   rq   r   rZ   setattrrz   r{   r|   rC   rb   )r;   rF   rD   rE   r}   r<   r   r   rA   Zdataclass_fieldglobalnslocalnsr   r   rB   rO   r(   r(   r.   collect_dataclass_fieldsX  sp    








2
r   ztype[PydanticDataclass]c                C  s   t  }i }||  | j D ]r\}}|jr8|||< q |j}tj|jg|j	R  }	t
|	|}	|j|	|jtjd}
|
jdur|
jn||
_|
||< q W d   n1 s0    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.
    rR   N)r   r   rG   r?   rp   r@   r   r   rq   r   r   r   ru   rv   r   r   )r;   rE   rF   rD   r}   r   r   rB   r   r   r   r(   r(   r.   rebuild_dataclass_fields  s*    
(r   )rM   r0   c                 C  s   |  d S )N_ra   rL   r(   r(   r.   rk     s    rk   c                 C  s   |  do|  d S )Nr   __r   rL   r(   r(   r.   is_valid_privateattr_name  s    r   z3Callable[[], Any] | Callable[[dict[str, Any]], Any]z'TypeIs[Callable[[dict[str, Any]], Any]])r   r0   c              	   C  s\   zt | }W n ttfy$   Y dS 0 t|j }t|dkoZt|d oZ|d jt	j
u S )zMWhether the provided default factory callable has a validated data parameter.Fr   r   )r   
ValueErrorry   list
parametersrz   lenr   rs   r   empty)r   sigr   r(   r(   r.   takes_validated_data_argument  s    r   )F)Jr,   
__future__r   Z_annotationsrl   rf   collections.abcr   r   	functoolsr   inspectr   r   r   rer	   typingr
   r   r   r   Zpydantic_corer   Ztyping_extensionsr   r   Ztyping_inspectionr   Ztyping_inspection.introspectionr   Zpydanticr   Zpydantic.errorsr    r   r   _configr   Z_docs_extractionr   Z_import_utilsr   r   Z_namespace_utilsr   _reprr   _utilsr   r8   r    r<   r"   mainr#   Z_dataclassesr$   r%   Z_decoratorsr&   r'   r3   r1   rC   r   rr   r   r   r   rk   r   r   r(   r(   r(   r.   <module>   s\    P.i-