U
    #i6                     @  s  d Z ddlmZ ddl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 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mZmZ erddlm Z  ddl!m"Z" ddl#m$Z$ d	dl%m&Z& d	dl'm(Z( G dd deZ)dddddZ*e	ddddd d!Z+d"d#d$d%d&d'd(Z,dd)d*d+d$d,d-d.d/d0d1Z-d"d2d%d3d4d5Z.d"dd6d7d8d9Z/ddd:d;d,d-d<d#d=d>d?Z0d2d6d@dAdBZ1d2d6d@dCdDZ2dS )EzmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.    )annotationsN)copy)	lru_cache)TYPE_CHECKINGAny)PydanticUndefined)PydanticUserError   )_typing_extra)ConfigWrapper)extract_docstrings_from_cls)import_cached_base_modelimport_cached_field_info)Representation)get_cls_type_hints_lenientis_classvaris_finalvarBaseMetadata   )	FieldInfo)	BaseModel)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   b/var/www/html/me.goteku.com/backend/venv/lib/python3.8/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    	r&   )maxsizeztype[BaseMetadata])r#   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   r%   c                 S  s
   || _ d S N)__dict__)selfr"   r   r   r!   __init__:   s    z@_general_metadata_cls.<locals>._PydanticGeneralMetadata.__init__N)r   r   r   r   r+   r   r   r   r!   _PydanticGeneralMetadata7   s   r,   )annotated_typesr   r   )r   r,   r   r   r!   r$   2   s    r$   z	type[Any]zdict[str, FieldInfo]r   None)clsfieldsconfig_wrapperr#   c                 C  s@   |j r<t| }| D ]$\}}|jd kr||kr|| |_qd S r(   )Zuse_attribute_docstringsr   itemsdescription)r/   r0   r1   Zfields_docsann_name
field_infor   r   r!   _update_fields_from_docstrings@   s
    r6   )typevars_mapztype[BaseModel]ztuple[type[Any], ...]zdict[str, Any] | Nonezdict[Any, Any] | Nonez%tuple[dict[str, FieldInfo], set[str]])r/   basesr1   types_namespacer7   r#   c                  s  t  }t }t| |}| jdi }i }	t }
| D ]\ } dkrJq6|jD ]} |rP|D ]D}t	| rbt
||r |jksbtd  dt|  d| dqbt fdd|jD }td  d	| j d
| d| d	t qPt|r|
  q6t|t|  tr|
  q6t s*q6| jrL dkrLtd dt| di d}|D ]}dd t|rt|ndD }t	| rb||krqb |krqb |krqbtd  d| j d|j dt qbzt|  t}|tkrtW n| tk
r    |kr.||}nPi }| jddd D ]}| t|di  qB |krtt!|  }n
||}Y n>X t"|  |#||}zt$|   W n tk
r   Y nX | jd } |j%krt&d||	 < q6|r
|	' D ]}|(|| qt)| |	| |	|
fS )a[  Collect the fields of a nascent pydantic model.

    Also collect the names of any ClassVars present in the type hints.

    The returned value is a tuple of two items: the fields dict, and the set of ClassVar names.

    Args:
        cls: BaseModel or dataclass.
        bases: Parents of the class, generally `cls.__bases__`.
        config_wrapper: The config wrapper instance.
        types_namespace: Optional extra namespace to look for types in.
        typevars_map: A dictionary mapping type variables to their concrete types.

    Returns:
        A tuple contains fields and class variables.

    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.
    __annotations__Zmodel_configzField "z" conflicts with member z of protected namespace "z".c                 3  s   | ]}  |s|V  qd S r(   
startswith).0xr4   r   r!   	<genexpr>   s    
 z'collect_model_fields.<locals>.<genexpr>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)r=   fieldr   r   r!   	<setcomp>   s    z'collect_model_fields.<locals>.<setcomp>r   zField name "z" in "z"" shadows an attribute in parent ""Nmodel_fieldsZ__pydantic_decorators__z0you can't override a field with a computed field)*r   r   r   r)   getsetr2   Zprotected_namespacesr<   hasattr
issubclassrI   	NameErrorgetattrtuplewarningswarnr   UserWarningr   add_is_finalvar_with_default_valr   is_valid_field_nameZ__pydantic_root_model__dataclassesis_dataclassr0   r   AttributeErrorZfrom_annotation	__bases__updater   #_warn_on_nested_alias_in_annotationfrom_annotated_attributedelattrZcomputed_fields
ValueErrorvaluesapply_typevars_mapr6   )r/   r8   r1   r9   r7   r   
FieldInfo_Z
type_hintsr   r0   Z
class_varsann_typeZprotected_namespacebZvalid_namespacesZgeneric_originbasedataclass_fieldsdefaultr5   Zmodel_fields_lookupr>   Z
decoratorsrE   r   r?   r!   collect_model_fieldsH   s    
















rh   str)rc   r4   r#   c                 C  sn   t  }t| dd }|rj|D ]N}t|rt|D ]4}t||r2|jd k	r2td| dt	   d S q2qd S )N__args__z `alias` specification on field "z5" must be set on outermost annotation to take effect.)
r   rO   r
   Zis_annotatedget_args
isinstancealiasrQ   rR   rS   )rc   r4   r   argsZanno_argZanno_type_argr   r   r!   r\      s    

r\   bool)type_valr#   c                 C  sH   t  }t| sdS |tkrdS t||r@|jtkr@|jd kr@dS dS d S )NFT)r   r   r   rl   rg   default_factory)rp   rq   r   r   r   r!   rU      s    rU   )r7   r1   ztype[StandardDataclass]zConfigWrapper | None)r/   r9   r7   r1   r#   c                C  sL  t  }i }| j}tt| }tj| j}|dk	r@|j|p<i }|	 D ]\}	}
t
|
j||}t|rjqH|
js|
jtjkr|
jtjkrqHt|
j|r|
jjr|
jjdkrHtd|	 dddqH|||
j}n|||
}|||	< |jtk	rHtt| |	||rHt| |	|j qH|r2| D ]}||| q|dk	rHt| || |S )aF  Collect the fields of a dataclass.

    Args:
        cls: dataclass.
        types_namespace: Optional extra namespace to look for types in.
        typevars_map: A dictionary mapping type variables to their concrete types.
        config_wrapper: The config wrapper instance.

    Returns:
        The dataclass fields.
    NFzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)code)r   __dataclass_fields__dictvarssysmodulesrJ   r   r)   r2   r
   Zeval_type_lenienttyper   initrg   rW   MISSINGrr   rl   Zinit_varr   r]   r   rO   setattrr`   ra   r6   )r/   r9   r7   r1   rb   r0   rf   Zcls_localnsZsource_moduler4   Zdataclass_fieldrc   r5   rE   r   r   r!   collect_dataclass_fields   sJ    



r}   )rD   r#   c                 C  s   |  d S )N_r;   rC   r   r   r!   rV   H  s    rV   c                 C  s   |  do|  d S )Nr~   __r;   rC   r   r   r!   is_valid_privateattr_nameL  s    r   )3r   
__future__r   Z_annotationsrW   rw   rQ   r   	functoolsr   typingr   r   Zpydantic_corer   Zpydantic.errorsr    r
   _configr   Z_docs_extractionr   Z_import_utilsr   r   _reprr   r   r   r   r-   r   r0   r   mainr   Z_dataclassesr   Z_decoratorsr   r   r&   r$   r6   rh   r\   rU   r}   rV   r   r   r   r   r!   <module>   sH    H