o
    ɝim                     @  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 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l/m0Z0m1Z1 erddl2m3Z3 ddl4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z: ddl;m<Z< G dd de.Z=dkd#d$Z>e	dld&d'Z?dmd0d1Z@dndod9d:ZAdpd@dAZBdqdDdEZCdrdHdIZDh dJZEh dKZFddLdsdSdTZGdtdWdXZHdddYdud\d]ZIdvd_d`ZJdwdbdcZKdwdddeZLdxdidjZMdS )yzmPrivate logic related to fields (the `Field()` function and `FieldInfo` class), and arguments to `Annotated`.    )annotationsN)Mapping)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'   V/var/www/html/ocr-read/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   
	r1   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__@   s   
z@_general_metadata_cls.<locals>._PydanticGeneralMetadata.__init__N)r.   r
   )r(   r)   r*   r+   r6   r'   r'   r'   r-   _PydanticGeneralMetadata=   s    r7   )annotated_typesr    r&   )r    r7   r'   r'   r-   r0   8   s   r0   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)r9   r;   r=   r?   r"   protected_namespacens_violationbvalid_namespacespnvalid_namespaces_strr'   r'   r-   _check_protected_namespacesF   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rc   )r   itemsdescription)r_   ra   rc   fields_docsr;   
field_infor'   r'   r-   _update_fields_from_docstringsq   s   
rj   title_generatorCallable[[str, FieldInfo], str]
field_nameri   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 )titlerJ   r<   	TypeError	__class__)rk   rm   ri   ro   r'   r'   r-   *_apply_field_title_generator_to_field_infox   s   



rr   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 rn   )alias_priorityaliasvalidation_aliasserialization_aliasrJ   r   generate_aliasescallabler<   rp   rq   r   )rs   rm   ri   rv   rw   rx   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_generatorrr   rs   r{   )r|   rm   ri   r}   r'   r'   r-   update_field_from_config   s   

r~   >   copy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|_#||_$nm|| % }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.
    rA   N)r   model_config)r9   r;   r=   r?   c                 3  s     | ]}t  |d u V  qd S r3   )rO   .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   )rO   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>6  s    z'collect_model_fields.<locals>.<setcomp>r'   zField name "z" in "z"" shadows an attribute in parent ""   rH   _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>.`)categoryrI   __pydantic_decorators__rB   z
 of class zf overrides symbol of same name in a parent class. This override with a computed_field is incompatible.):r   r   	__bases__reversedrO   updater   get_model_type_hintssafe_get_annotationssetrf   r^   r9   r(   is_classvar_annotationaddr   any_deprecated_method_namesrM   _deprecated_classmethod_namesis_valid_field_name__pydantic_root_model__	NameErrorgetdataclassesis_dataclassra   rU   rV   r*   rW   from_annotationr   CLASS	_complete_original_annotation_copyrJ   r   r   __get___attributes_setfrom_annotated_attribute_original_assignment_qualifiersis_requiredr   delattrAttributeErrorr4   computed_fieldsrp   r~   valuesapply_typevars_mapuse_attribute_docstringsrj   )r_   r|   r   r   
FieldInfo_r=   parent_fields_lookupbasemodel_fields
type_hintsr   ra   
class_varsr;   ann_type	evaluatedgeneric_origindataclass_fieldsri   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   pushrA   rf   r   rg   r   	eval_typer   types_namespacer   replace_typesr   r   r   r   r   r   r~   )r_   r|   r   r   r   rebuilt_fieldsf_nameri   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__re   )%r   r   __dataclass_fields__r   __mro__r   r   r   rf   r   r   r   try_eval_typetyper   initr   MISSINGdefault_factoryrJ   init_varr   r   r   	DATACLASSr   r   r   r~   r   rO   setattrr   r   r   rj   rM   )r_   r|   r   r   r   ra   r   r   r;   dataclass_field	base_annsglobalnslocalnsr   r   ri   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   rA   rf   r   rg   r   r   r   r   r   r   r   r   r   r   r~   )r_   r|   r   r   r   r   r   ri   r   r   r   r'   r'   r-   rebuild_dataclass_fields8  s4   


r   r   c                 C  s   |  d S )N_rL   r   r'   r'   r-   r   f  s   r   c                 C  s   |  do
|  d S )Nr   __r   r   r'   r'   r-   is_valid_privateattr_namej  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   rP   rp   list
parametersr   rT   r   r   r   empty)r   sigr  r'   r'   r-   takes_validated_data_argumentn  s   (r  )r.   r
   r/   r    )r/   r2   )
r9   r:   r;   r<   r=   r>   r?   r<   r/   r@   )F)r_   r`   ra   rb   rc   rd   r/   r@   )rk   rl   rm   r<   ri   r!   )rs   rt   rm   r<   ri   r!   )r|   r   rm   r<   ri   r!   r/   r@   )
r_   r   r|   r   r   r   r   r   r/   r   )
r_   r   r|   r   r   r   r   r   r/   rb   )
r_   r   r|   r   r   r   r   r   r/   rb   )
r_   r   r|   r   r   r   r   r   r/   rb   )r   r<   r/   rd   )r   r   r/   r  )Nr+   
__future__r   _annotationsr   rU   collections.abcr   	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   r8   r    ra   r!   mainr"   _dataclassesr#   r$   _decoratorsr%   r&   r1   r0   r^   rj   rr   r{   r~   r   r   r   r   r   r   r   r   r  r'   r'   r'   r-   <module>   sd    

+


2 
H1
l
.
