a
    _gB                     @  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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& er"ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 G dd de$Z1dddddZ2edd d!d"d#d$Z3d%d&d'd(d)d*d+Z4dd,d-d.d'd/d0d1d2d3d4Z5d%d5d(d6d7d8Z6d%dd9d:d;d<Z7dddd=d>d/d0d?d&d@dAdBZ8d5d9dCdDdEZ9d5d9dCdFdGZ:dHdIdJdKdLZ;dS )MzmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.    )annotationsN)copy)	lru_cache)	Parameterismethoddescriptor	signature)TYPE_CHECKINGAnyCallablePattern)PydanticUndefined)TypeIs)PydanticUserError   )_typing_extra)ConfigWrapper)extract_docstrings_from_cls)import_cached_base_modelimport_cached_field_info)
NsResolver)Representation)can_be_positional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    h/var/www/html/cobodadashboardai.evdpl.com/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    	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$   r0   r    r    r    r&   _PydanticGeneralMetadata9   s   r1   )annotated_typesr   r   )r   r1   r    r    r&   r)   4   s    r)   z	type[Any]zdict[str, FieldInfo]r   None)clsfieldsconfig_wrapperr(   c                 C  s@   |j r<t| }| D ]$\}}|jd u r||v r|| |_qd S r-   )Zuse_attribute_docstringsr   itemsdescription)r4   r5   r6   Zfields_docsann_name
field_infor    r    r&   _update_fields_from_docstringsB   s
    r;   )typevars_mapztype[BaseModel]ztuple[type[Any], ...]zNsResolver | Nonezdict[Any, Any] | Nonez%tuple[dict[str, FieldInfo], set[str]])r4   basesr6   ns_resolverr<   r(   c                C  s  t  }t }i }t|D ]}t|dd }	r||	 qtj| |d}
| jdi }i }t	 }|

 D ]0\}\}}|dkr~qf|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rL||sb|d|j df7 }n||s||f7 }qtd| d| j d| d| d	t qt|r|| qft|t| |tr|| qft|sqf| jr|dkrtd|dt| di d}|D ]}dd t |r,t!|ndD }t||r||u rNq||v r\q||vrjqtd| d| j" d|j" dt qzt| |t}|tu rt#W nX t#y   ||v r|$|}||_%n(||v rt&|| }n|$|}||_%Y nj0 t'|| t||r<t(|j)r<|j)*d| |_)|+||}||_%zt,| | W n t#yp   Y n0 | jd }||j-v rt.d|||< qf|r|/ D ]}|0| qt1| || ||fS )ab  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.
        ns_resolver: Namespace resolver to use when getting model annotations.
        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.
    Z__pydantic_fields__N)r>   __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 ""Z__pydantic_decorators__z0you can't override a field with a computed field)2r   r   reversedgetattrupdater   Zget_model_type_hintsr.   getsetr7   Zprotected_namespaces
isinstancer   matchstr
startswithhasattr
issubclass	NameErrorpatternwarningswarnr!   UserWarningis_classvar_annotationadd_is_finalvar_with_default_valr   is_valid_field_nameZ__pydantic_root_model__dataclassesis_dataclassr5   r#   AttributeErrorZfrom_annotation	evaluatedr   #_warn_on_nested_alias_in_annotationr   default__get__from_annotated_attributedelattrZcomputed_fields
ValueErrorvaluesapply_typevars_mapr;   )r4   r=   r6   r>   r<   r   
FieldInfo_Zparent_fields_lookupbaseZmodel_fieldsZ
type_hintsr   r5   Z
class_varsr9   ann_typer`   Zprotected_namespaceZns_violationbZvalid_namespacesZpnZgeneric_origindataclass_fieldsrb   r:   Z
decoratorsrF   r    r    r&   collect_model_fieldsJ   s    



















rn   rP   )rk   r9   r(   c                 C  sn   t  }t| dd }|rj|D ]N}t|rt|D ]4}t||r2|jd u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   rJ   r   Zis_annotatedget_argsrN   aliasrV   rW   rX   )rk   r9   r   argsZanno_argZanno_type_argr    r    r&   ra      s    

ra   bool)type_valr(   c                 C  sJ   t  }t| sdS |tu r dS t||rB|jtu rB|jd u rBdS dS d S )NFT)r   r   Zis_finalvarr   rN   rb   default_factory)rt   ru   r   r    r    r&   r[     s    
r[   )r>   r<   r6   ztype[StandardDataclass]zConfigWrapper | None)r4   r>   r<   r6   r(   c             	   C  s  t  }i }|pt }| j}t| jD ]2}t|s6q$|| | D ]\}}	||j	
di vrhqL|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}n|||	}|||< |jturLtt| |||rLt| ||j qLW d   q$1 sN0    Y  q$|rz| D ]}|| qh|durt| || |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.
    r?   FzDataclass field zD has init=False and init_var=True, but these are mutually exclusive.zclashing-init-and-init-var)codeN)r   r   __dataclass_fields__rI   __mro__r]   r^   pushr7   r.   rL   Ztypes_namespacer   Ztry_eval_typetyperY   initrb   MISSINGrv   rN   Zinit_varr   rd   r   rJ   setattrrg   rh   r;   )r4   r>   r<   r6   ri   r5   rm   rj   r9   Zdataclass_fieldglobalnslocalnsrk   _r:   rF   r    r    r&   collect_dataclass_fields  sV    






2
r   )rD   r(   c                 C  s   |  d S )Nr   rQ   rC   r    r    r&   r\   s  s    r\   c                 C  s   |  do|  d S )Nr   __r   rC   r    r    r&   is_valid_privateattr_namew  s    r   z3Callable[[], Any] | Callable[[dict[str, Any]], Any]z'TypeIs[Callable[[dict[str, Any]], Any]])rv   r(   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   rf   	TypeErrorlist
parametersrg   lenr   rb   r   empty)rv   sigr   r    r    r&   takes_validated_data_argument{  s    r   )<r$   
__future__r   Z_annotationsr]   rV   r   	functoolsr   inspectr   r   r   typingr   r	   r
   r   Zpydantic_corer   Ztyping_extensionsr   Zpydantic.errorsr    r   _configr   Z_docs_extractionr   Z_import_utilsr   r   Z_namespace_utilsr   _reprr   _utilsr   r2   r   r5   r   mainr   Z_dataclassesr   Z_decoratorsr   r   r+   r)   r;   rn   ra   r[   r   r\   r   r   r    r    r    r&   <module>   sP    4Y