a
    “˜ëjE{  ã                   @  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mZ ddlmZ ddl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 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/m0Z0 ddl1m2Z2m3Z3 e�rjddl4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z;m<Z< ddl=m>Z> G dd„ de0ƒZ?ej@f i e,¤ŽG d d!„ d!ƒƒZAd"d#d$œd%d&„ZBe	d'd(œd)d*„ƒZCd+d,d-d,d.d/œd0d1„ZDdpd3d4d5d.d6œd7d8„ZEd9d,d:d;œd<d=„ZFd>d,d:d?œd@dA„ZGdBd,d:d.dCœdDdE„ZHh dF£ZIh dG£ZJddHœdIdBdJdKdLdMœdNdO„ZKdIdBdJdPdQdMœdRdS„ZLd:dJdPd5d:dTœdUdV„ZMdddWœdXdBdYdZd4dMœd[d\„ZNd]dBdJdPd4dMœd^d_„ZOd,d5d`œdadb„ZPd,d5d`œdcdd„ZQdedfdgœdhdi„ZRdd2djœd"dkdld5d"dmœdndo„ZSdS )qzmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.é    )ÚannotationsN)ÚMapping)Úcache)Ú	ParameterÚismethoddescriptor)ÚPattern)ÚTYPE_CHECKINGÚAnyÚCallableÚTypeVarÚcast)ÚPydanticUndefined)ÚTypeIs)ÚAnnotationSource)ÚPydanticDeprecatedSince211)ÚPydanticUserErroré   )ÚAliasGeneratoré   )Ú	_genericsÚ_typing_extra)ÚConfigWrapper)Úextract_docstrings_from_cls)Úimport_cached_base_modelÚimport_cached_field_info)Ú
slots_true)Ú
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(   úY/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/pydantic/_internal/_fields.pyr'   '   s   r'   c                   @  s   e Zd ZU ded< ded< dS )ÚPydanticExtraInfor	   Ú
annotationÚboolÚcompleteN)r)   r*   r+   Ú__annotations__r(   r(   r(   r.   r/   -   s   
r/   r	   r!   )ÚmetadataÚreturnc                  K  s
   t ƒ | ƒS )z¿Create a new `_PydanticGeneralMetadata` class with the given metadata.

    Args:
        **metadata: The metadata to add.

    Returns:
        The new `_PydanticGeneralMetadata` class.
    )Ú_general_metadata_cls©r4   r(   r(   r.   Úpydantic_general_metadata4   s    	r8   ztype[BaseMetadata])r5   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	   r7   c                 S  s
   || _ d S ©N)Ú__dict__)Úselfr4   r(   r(   r.   Ú__init__H   s    z@_general_metadata_cls.<locals>._PydanticGeneralMetadata.__init__N)r)   r*   r+   r,   r<   r(   r(   r(   r.   Ú_PydanticGeneralMetadataE   s   r=   )Úannotated_typesr!   r'   )r!   r=   r(   r(   r.   r6   @   s    r6   ztuple[str | Pattern[str], ...]Ústrztuple[type[Any], ...]ÚNone)Úprotected_namespacesÚann_nameÚbasesÚcls_namer5   c                 C  s@  t ƒ }| D �].}d}t|tƒr.| |¡d u}nt|tƒrB| |¡}|r
|D ]J}t||ƒrJt||ƒrr|t|di ƒv sJt	d|›dt||ƒ› d|›d�ƒ‚qJg }| D ]J}	t|	tƒrÌ|	 |¡sè| 
d|	j›d�¡ qž| |	¡sž| 
d	|	› d	�¡ qžd
d |¡› t|ƒdk�rd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)rA   rB   rC   rD   r#   Zprotected_namespaceZns_violationÚbZvalid_namespacesZpnZvalid_namespaces_strr(   r(   r.   Ú_check_protected_namespacesN   s>    




ÿÿ


&ÿür]   Fz	type[Any]zdict[str, FieldInfo]r1   )ÚclsÚfieldsÚuse_inspectr5   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_docsrB   Ú
field_infor(   r(   r.   Ú_update_fields_from_docstringsy   s    re   zCallable[[str, FieldInfo], str]r"   )Útitle_generatorÚ
field_namerd   c                 C  s>   |j d u r:| ||ƒ}t|tƒs4td| › d|j› �ƒ‚||_ d S )Nzfield_title_generator ú must return str, not )ÚtitlerN   r?   Ú	TypeErrorÚ	__class__)rf   rg   rd   ri   r(   r(   r.   Ú*_apply_field_title_generator_to_field_info€   s
    


rl   z%Callable[[str], str] | AliasGenerator)Úalias_generatorrg   rd   c                 C  s  |j du s4|j dks4|jdu s4|jdu s4|jdu �r
d\}}}t| tƒrZ|  |¡\}}}n0t| ƒrŠ| |ƒ}t|tƒsŠt	d| › d|j
› �ƒ‚|j du sž|j dkr¤d|_ |j dkrÌt||ƒ|_t||ƒ|_||_|jdu rÜ||_|jdu ròt||ƒ|_|jdu �r
t||ƒ|_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 rh   )Zalias_priorityÚaliasÚvalidation_aliasÚserialization_aliasrN   r   Zgenerate_aliasesÚcallabler?   rj   rk   r   )rm   rg   rd   rn   ro   rp   r(   r(   r.   Ú$_apply_alias_generator_to_field_info�   s:    ÿþýüû





rr   r   )Úconfig_wrapperrg   rd   r5   c                 C  s<   |j p
| j }|dur t|||ƒ | jdur8t| j||ƒ 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_generatorrl   rm   rr   )rs   rg   rd   rt   r(   r(   r.   Úupdate_field_from_config¿   s
    

ru   >   ÚdictÚjsonZ_iterZ_calculate_keysÚcopyZ_copy_and_set_values>
   Zupdate_forward_refsÚvalidateÚ
_get_valueZ
parse_fileZ	parse_rawZ	parse_objZschemaZfrom_ormZschema_jsonZ	construct)Útypevars_mapztype[BaseModel]r   zMapping[TypeVar, Any] | Nonez?tuple[dict[str, FieldInfo], PydanticExtraInfo | None, set[str]])r^   rs   Úns_resolverr{   r5   c             
     sŽ  t ƒ }tƒ ‰ | j}i }t|ƒD ]}t|ddƒ }r| |¡ qtj| |d�}	t | ¡}
i }t	ƒ }|	 
¡ D �]à\}\}}|dkr€qht|j||| jd� t |¡rª| |¡ qht| |tƒ‰ˆturüt‡ ‡fdd„tD ƒƒsøtˆdƒrüt‡ ‡fd	d„tD ƒƒrüt‰t|ƒ�sqh| j�r*|d
k�r*td|›d�ƒ‚|D ]š}t||ƒ�r.||
v�rL�q.t| di ƒ d¡}||u �rl�q.dd„ t |¡�rˆt |¡ndD ƒ}||v �rž�q.tjd|› d| j› d|j› d�tdd� �q.ˆtu �r6||
v �sè||v�r|j |t!j"d�}||_#|�s4d|_$n(||  %¡ }|�r0t&|||dd�}n|}nÌt'ˆ|ƒ�rlt(ˆj)ƒ�rlˆj) *d| ¡}|ˆ_)|ˆj+d< |j,|ˆt!j"d�}ˆ|_-||_#|�s˜d|_$nFd|j.v �rÞ| /¡ �sÞtjd|›d|›d |›d!�t0dd"� | |¡ qhzt1| |ƒ W n t2�y    Y n0 | j3d# }||j4v �r0t5d$|›d%| j›d&�ƒ‚|||< |j$rht6|||ƒ qh|j7�r^t8| |ƒ d}d'|	v �r„|	d' \}}t9||d(�}|||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 three-tuple containing the model fields, the `PydanticExtraInfo` instance if the `__pydantic_extra__` annotation is set,
        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.
    rE   N)r|   Zmodel_config)rA   rB   rC   rD   c                 3  s   | ]}t ˆ |d ƒˆu V  qd S r9   )rS   ©Ú.0Z	depr_name©Z
BaseModel_Zassigned_valuer(   r.   Ú	<genexpr>&  ó    z'collect_model_fields.<locals>.<genexpr>Ú__func__c                 3  s(   | ] }t t ˆ |d ƒdd ƒˆju V  qd S )Nr‚   )rS   r‚   r}   r   r(   r.   r€   *  s   ÿÚ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)r~   Úfieldr(   r(   r.   Ú	<setcomp>G  s   z'collect_model_fields.<locals>.<setcomp>r(   zField name "z" in "z"" shadows an attribute in parent "ú"é   rL   ©Ú_sourceFT©r|   r{   ÚlenientÚ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>.`)ÚcategoryrM   Z__pydantic_decorators__rF   z
 of class zf overrides symbol of same name in a parent class. This override with a computed_field is incompatible.Z__pydantic_extra__©r0   r2   ):r   r   Ú	__bases__ÚreversedrS   Úupdater   Zget_model_type_hintsÚsafe_get_annotationsÚsetrb   r]   rA   r)   Úis_classvar_annotationÚaddr   ÚanyÚ_deprecated_method_namesrQ   Ú_deprecated_classmethod_namesÚis_valid_field_nameZ__pydantic_root_model__Ú	NameErrorÚgetÚdataclassesÚis_dataclassr_   rY   rZ   r+   r[   Úfrom_annotationr   ÚCLASSÚ_original_annotationÚ	_completeZ_copyÚ_recreate_field_inforN   r   r�   Ú__get__Z_attributes_setÚfrom_annotated_attributeÚ_original_assignmentZ_qualifiersZis_requiredr   ÚdelattrÚAttributeErrorr:   Zcomputed_fieldsrj   ru   Úuse_attribute_docstringsre   r/   )r^   rs   r|   r{   Ú
FieldInfo_rC   Zparent_fields_lookupÚbaseZmodel_fieldsZ
type_hintsZcls_annotationsr_   Z
class_varsrB   Úann_typeÚ	evaluatedZgeneric_originÚdataclass_fieldsrd   Zparent_field_infor�   Z
decoratorsZpydantic_extra_infoÚannr2   r(   r   r.   Úcollect_model_fieldsà   sà     
ü

þûþú

ÿ

ÿ
ÿü

ÿ
þú

ÿ

þr³   zMapping[TypeVar, Any]z5tuple[dict[str, FieldInfo], PydanticExtraInfo | None]c          	      C  s¸   i }|  | ¡�’ | j ¡ D ]<\}}|jr2|||< qt|||dd�}t|||ƒ |||< q| jdurŒ| jjsŒtt	j
| jjg|j¢R Ž dd�}n| j}W d  ƒ n1 s¦0    Y  ||f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.

    Returns:
        A two-tuple, the first element being the rebuilt fields, the second element being
        the rebuild `PydanticExtraInfo` instance, if available.

    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.
    Fr�   NTr’   )ÚpushrE   rb   r¥   r¦   ru   Z__pydantic_extra_info__r2   r/   r   Ú	eval_typer0   Útypes_namespace)	r^   rs   r|   r{   Úrebuilt_fieldsÚf_namerd   Ú	new_fieldZrebuilt_extra_infor(   r(   r.   Úrebuild_model_fields´  s*    
ÿ
ÿÿü$rº   )rd   r|   r{   rŽ   r5   c          
      C  sÔ   t ƒ }| j}|r8t | j|¡}tj|g|j¢R Ž \}}n:tj| jg|j¢R Ž }t ||¡}tj|g|j¢R Ž }d}| j	 }t
u r’|j|tjd�}	n|j||tjd�}	||	_	||	_|	jd urÀ|	jn||	_|sÐd|	_|	S )NTr‹   F)r   rc   r   Úreplace_typesr¤   r   Útry_eval_typer¶   rµ   r©   r   r¢   r   r£   r¨   r¥   )
rd   r|   r{   rŽ   r­   Úexisting_descr²   r°   Zassignr¹   r(   r(   r.   r¦   ã  s<    ÿþÿþÿþr¦   )r|   r{   ztype[StandardDataclass]zNsResolver | Nonezdict[Any, Any] | Nonec             	   C  sØ  t ƒ }i }|ptƒ }| j}t| jƒD �]n}t |¡s6q$| |¡��@ | ¡ D �]$\}}	t	 
|¡}
||
vrjqL|j\}}t	 |	j||¡\}}t	 |¡r”qL|	js´|	jtju r´|	jtju r´qLt|	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|_||_|||< t|||ƒ |jturLtt| ||ƒ|ƒrLt| ||jƒ qLW d  ƒ q$1 �sŠ0    Y  q$|�r¶|  ¡ D ]}| !|¡ �q¤|j"�rÔt#| |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‹   NZ__is_pydantic_dataclass__ra   )%r   r   Z__dataclass_fields__r”   Ú__mro__r    r¡   r´   rb   r   r–   r¶   r¼   Útyper˜   Úinitr�   ÚMISSINGÚdefault_factoryrN   Zinit_varr   r¨   r   Ú	DATACLASSr©   r¥   r¤   ru   r   rS   ÚsetattrÚvaluesZapply_typevars_mapr¬   re   rQ   )r^   rs   r|   r{   r­   r_   r±   r®   rB   Zdataclass_fieldZ	base_annsÚglobalnsÚlocalnsr¯   r°   rd   r‡   r(   r(   r.   Úcollect_dataclass_fields  st    




ÿ
þ
ý
þ
ÿ
ÿÿ2
ûrÉ   ztype[PydanticDataclass]c                C  sÂ   t ƒ }i }| | ¡�š | j ¡ D ]~\}}|jr8|||< q |j}tj|jg|j	¢R Ž }	t
 |	|¡}	|j|	|jtjd�}
|
jdur„|
jn||
_t|||
ƒ |
||< q W d  ƒ n1 s´0    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´   rE   rb   r¥   rc   r   rµ   r¤   r¶   r   r»   r¨   r©   r   rÄ   ru   )r^   rs   r|   r{   r­   r·   r¸   rd   r½   r²   r¹   r(   r(   r.   Úrebuild_dataclass_fields{  s,    
ÿþý(rÊ   )r†   r5   c                 C  s   |   d¡ S )NÚ_©rP   r…   r(   r(   r.   r�   ©  s    r�   c                 C  s   |   d¡o|   d¡ S )NrË   Ú__rÌ   r…   r(   r(   r.   Úis_valid_privateattr_name­  s    rÎ   z3Callable[[], Any] | Callable[[dict[str, Any]], Any]z'TypeIs[Callable[[dict[str, Any]], Any]])rÃ   r5   c              	   C  s^   zt  | ¡}W n ttfy&   Y dS 0 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   Zsignature_no_evalrT   rj   ÚlistÚ
parametersrÆ   rX   r   r�   r   Úempty)rÃ   ÚsigrÐ   r(   r(   r.   Útakes_validated_data_argument±  s    rÓ   )Úvalidated_dataÚcall_default_factoryz:Callable[[], Any] | Callable[[dict[str, Any]], Any] | Nonezdict[str, Any] | None)r�   rÃ   rÔ   rÕ   r5   c                C  s`   ddl m} |du r|| ƒS |r\t|d�rLtd|ƒ}|du rDtdƒ‚||ƒS td|ƒ}|ƒ S tS )zMResolve the default value using either a static default or a default_factory.r   )Úsmart_deepcopyN)rÃ   zCallable[[dict[str, Any]], Any]zpThe default factory requires the 'validated_data' argument, which was not provided when calling 'get_default()'.zCallable[[], Any])Ú_utilsrÖ   rÓ   r   rT   r   )r�   rÃ   rÔ   rÕ   rÖ   Zfacr(   r(   r.   Úresolve_default_valueÁ  s    

ÿ
rØ   )F)Tr,   Ú
__future__r   Z_annotationsr    rY   Úcollections.abcr   Ú	functoolsr   Úinspectr   r   Úrer   Útypingr   r	   r
   r   r   Zpydantic_corer   Ztyping_extensionsr   Ztyping_inspection.introspectionr   Zpydanticr   Zpydantic.errorsr   Úaliasesr   Ú r   r   Ú_configr   Z_docs_extractionr   Z_import_utilsr   r   Z_internal_dataclassr   Z_namespace_utilsr   Ú_reprr   r×   r   r   r>   r!   r_   r"   Úmainr#   Z_dataclassesr$   r%   Z_decoratorsr&   r'   Z	dataclassr/   r8   r6   r]   re   rl   rr   ru   r›   rœ   r³   rº   r¦   rÉ   rÊ   r�   rÎ   rÓ   rØ   r(   r(   r(   r.   Ú<module>   sp   +2û U/0ûl.û