o
    $6dIg                     @  sX  U 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 ddlmZmZmZmZ ddlmZmZmZ dd	lmZmZ d
dl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$m%Z%m&Z& ddl'm(Z(m)Z)m*Z* ddl+m,Z, ddl-m.Z.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z: ddl;m<Z<m=Z=m>Z> ddl?m@Z@mAZA ddlBmCZC ejDrddlEmFZF d
dlGmHZH ne ZIeeJeKeLe*e(eCfZMdeNd< eOjPZQG dd  d eRZSed!efd"G d#d$ d$eZTdWd+d,ZUdXd5d6ZVdYd8d9ZWdZd?d@ZXd!dAd[dGdHZYd\dNdOZZG dPdQ dQej[Z\d]dSdTZ]d]dUdVZ^dS )^z"Private logic for creating models.    )annotationsN)ABCMeta)partial)FunctionType)AnyCallableGenericMapping)PydanticUndefinedSchemaSerializerSchemaValidator)dataclass_transform
deprecated   )PydanticUndefinedAnnotationPydanticUserError)Field	FieldInfoModelPrivateAttrPrivateAttr)PydanticDeprecatedSince20   )ConfigWrapper)collect_invalid_schemasflatten_schema_defsinline_schema_defs)ComputedFieldInfoDecoratorInfosPydanticDescriptorProxy)apply_discriminators)collect_model_fieldsis_valid_field_nameis_valid_privateattr_name)GenerateSchema)PydanticGenericMetadataget_model_typevars_map)
MockValSerset_model_mocks)CallbackGetCoreSchemaHandler)get_cls_types_namespaceis_classvarparent_frame_namespace)ClassAttributeis_valid_identifier)ValidateCallWrapper)	Signature	BaseModelztuple[Any, ...]IGNORED_TYPESc                      s"   e Zd ZdZd
 fdd	Z  ZS )_ModelNamespaceDictz{A dictionary subclass that intercepts attribute setting on model classes and
    warns about overriding of decorators.
    kstrvobjectreturnNonec                   sL   |  |d }|r||urt|trtd| d|jj d t ||S )N`z"` overrides an existing Pydantic `z` decorator)	get
isinstancer   warningswarnZdecorator_infoZdecorator_reprsuper__setitem__)selfr4   r6   existing	__class__ }C:\Users\jesus\OneDrive\Desktop\erpjis_fastapi\backend\jisbackend\Lib\site-packages\pydantic/_internal/_model_construction.pyr@   :   s   z_ModelNamespaceDict.__setitem__)r4   r5   r6   r7   r8   r9   )__name__
__module____qualname____doc__r@   __classcell__rE   rE   rC   rF   r3   5   s    r3   T)Zkw_only_defaultZfield_specifiersc                      sx   e Zd Z		d%d& fddZejsd'ddZed(ddZd) fddZ	e
d*ddZeed ed!d+d#d$Z  ZS ),ModelMetaclassNTcls_namer5   basestuple[type[Any], ...]	namespacedict[str, Any]__pydantic_generic_metadata__PydanticGenericMetadata | None#__pydantic_reset_parent_namespace__boolkwargsr   r8   typec                   s  |r9|  |\}}}	t|||}
|
j|d< t||
j||}|r9d|v r5|d  d' fd	d
}||d< nt|d< ||d< i |	||d< |
jrMt|| t	 j
| |||fi |}ddlm} t|jdd |_|j|ju rqdnd|_t||_|r||_nlt|di ddt|ddprrtfddD stfddD  }ddd |D }d| d}d| d}t|vrdd d |D |g }|d!|j d"| d#7 }t|ddd$|_d|_| D ]
\}}||| q|rt t! |_"t|d%d}t#|t$rt%|}t&||}t'|||
| t(|||
d|d& t	||j)di | |S t	 j
| |||fi |S )(a  Metaclass for creating Pydantic models.

        Args:
            cls_name: The name of the class to be created.
            bases: The base classes of the class to be created.
            namespace: The attribute dictionary of the class to be created.
            __pydantic_generic_metadata__: Metadata for generic models.
            __pydantic_reset_parent_namespace__: Reset parent namespace.
            **kwargs: Catch-all for any other keyword arguments.

        Returns:
            The new class created by the metaclass.
        model_configmodel_post_initrA   r1   _ModelMetaclass__contextr   r8   r9   c                   s   t | |  | | dS )zWe need to both initialize private attributes and call the user-defined model_post_init
                        method.
                        N)init_private_attributes)rA   rZ   )original_model_post_initrE   rF   wrapped_model_post_initj   s   
z7ModelMetaclass.__new__.<locals>.wrapped_model_post_init__class_vars____private_attributes__r   r0   Z__pydantic_base_init__FNrR   
parametersrE   __parameters__c                 3  s    | ]}| v V  qd S NrE   .0x)r`   rE   rF   	<genexpr>   s    z)ModelMetaclass.__new__.<locals>.<genexpr>c                 3  s    | ]	}| vr|V  qd S rb   rE   rc   )parent_parametersrE   rF   rf      s    z, c                 S  s   g | ]}t |qS rE   )r5   rc   rE   rE   rF   
<listcomp>   s    z*ModelMetaclass.__new__.<locals>.<listcomp>ztyping.Generic[]zJAll parameters must be present on typing.Generic; you should inherit from .c                 S  s   g | ]}|j qS rE   )rG   rc   rE   rE   rF   rh      s    z- Note: `typing.Generic` must go last: `class (z): ...`))originargsr`   __pydantic_parent_namespace__)raise_errorstypes_namespace)rA   r1   rZ   r   r8   r9   )*_collect_bases_datar   Z	for_modelZconfig_dictinspect_namespaceignored_typesr[   frozenset_default_hash_funcr?   __new__mainr1   getattr__init__Z__pydantic_custom_init__rY   Z__pydantic_post_init__r   buildZ__pydantic_decorators__rR   r;   alltuplejoinr   rG   	TypeError__pydantic_complete__items__set_name__build_lenient_weakvaluedictr+   rn   r<   dictunpack_lenient_weakvaluedictr)   set_model_fieldscomplete_model_classZ__pydantic_init_subclass__)mcsrM   rN   rP   rR   rT   rV   Zbase_field_names
class_varsZbase_private_attributesconfig_wrapperprivate_attributesr]   clsr1   Zcombined_parametersZparameters_strZgeneric_type_labelerror_messageZ	bases_strnameobjZparent_namespacerp   rC   )r\   r`   rg   rF   rv   D   s   





zModelMetaclass.__new__itemc                 C  s`   | j d}|r||v r|| S |dkr,t| dd}t|tr,| }|dur,t| dS t|)zNThis is necessary to keep attribute access working for class attribute access.r_   __pydantic_core_schema____pydantic_validator__N)__dict__r;   rx   r<   r&   ZrebuildAttributeError)rA   r   r   Zmaybe_mock_validatorZrebuilt_validatorrE   rE   rF   __getattr__   s   

zModelMetaclass.__getattr__rm   Mapping[str, object]c                 O  s   t  S rb   )r3   )r   rm   rV   rE   rE   rF   __prepare__   s   zModelMetaclass.__prepare__instancec                   s   t |do
t |S )zsAvoid calling ABC _abc_subclasscheck unless we're pretty sure.

        See #3829 and python/cpython#92810
        r   )hasattrr?   __instancecheck__)rA   r   rC   rE   rF   r      s   z ModelMetaclass.__instancecheck__6tuple[set[str], set[str], dict[str, ModelPrivateAttr]]c                 C  sp   ddl m} t }t }i }| D ]"}t||r2||ur2|t|di   ||j ||j q|||fS )Nr   r0   model_fields)	rw   r1   set
issubclassupdaterx   keysr^   r_   )rN   r1   field_namesr   r   baserE   rE   rF   rq      s   
z"ModelMetaclass._collect_bases_dataEThe `__fields__` attribute is deprecated, use `model_fields` instead.)categorydict[str, FieldInfo]c                 C  s   t dt | jS )Nr   )r=   r>   DeprecationWarningr   rA   rE   rE   rF   
__fields__   s   zModelMetaclass.__fields__)NT)rM   r5   rN   rO   rP   rQ   rR   rS   rT   rU   rV   r   r8   rW   )r   r5   r8   r   )rm   r   rV   r   r8   r   )r   r   r8   rU   )rN   rO   r8   r   )r8   r   )rG   rH   rI   rv   typingTYPE_CHECKINGr   classmethodr   r   staticmethodrq   propertyr   r   r   rK   rE   rE   rC   rF   rL   B   s     ~
rL   rA   r1   	__contextr   r8   r9   c                 C  s@   i }| j  D ]\}}| }|tur|||< qt| d| dS )a  This function is meant to behave like a BaseModel method to initialise private attributes.

    It takes context as an argument since that's what pydantic-core passes when calling it.

    Args:
        self: The BaseModel instance.
        __context: The context.
    Z__pydantic_private__N)r_   r   get_defaultr
   object_setattr)rA   r   Zpydantic_privater   Zprivate_attrdefaultrE   rE   rF   r[      s   	r[   rP   rQ   rs   rO   base_class_varsset[str]base_class_fieldsdict[str, ModelPrivateAttr]c              	   C  s<  |t  }i }| di }d|v sd| v rtdt }t|  D ]\}}	|dkr*q!t|	tr?|	j| d kr?|	j	
| d r?q!t|	|sJ|	jjdkrP|| q!t|	tr{|
drbtd	|d
t|rstdd| d|d
|	||< | |= q!t|	trt|s|dpd}
td|
d|d
|
drq!t|r||vst|| st|	d||< | |= q!||v rq!||vr||v rtd|dddt|	trtd|dddtd| d|	d| dddq!| D ]+\}}t|r||vr||vrt|s||vrt|dddkrt ||< q|S )a  Iterate over the namespace and:
    * gather private attributes
    * check for items which look like fields but are not (e.g. have no annotation) and warn.

    Args:
        namespace: The attribute dictionary of the class to be created.
        ignored_types: A tuple of ignore types.
        base_class_vars: A set of base class class variables.
        base_class_fields: A set of base class fields.

    Returns:
        A dict contains private attributes info.

    Raises:
        TypeError: If there is a `__root__` field in model.
        NameError: If private attribute name is invalid.
        PydanticUserError:
            - If a field does not have a type annotation.
            - If a field on base class was overridden by a non-annotated attribute.
    __annotations__Z__root__zUTo define root models, use `pydantic.RootModel` rather than a field called '__root__'rX   rH   rI   	functools__zXPrivate attributes must not use dunder names; use a single underscore prefix instead of rj   zJPrivate attributes must not use valid field names; use sunder names, e.g. _z instead of Zmy_fieldz>Fields must not use names with leading underscores; e.g., use )r   zField z defined on a base class was overridden by a non-annotated attribute. All field definitions, including overrides, require a type annotation.zmodel-field-overridden)codez requires a type annotationzmodel-field-missing-annotationz)A non-annotated attribute was detected: `z = z3`. All model fields require a type annotation; if `z` is not meant to be a field, you may be able to resolve this error by annotating it as a `ClassVar` or updating `model_config['ignored_types']`.N)r2   r;   r~   r   listr   r<   rW   rH   rI   
startswithrD   addr   	NameErrorr!   r   lstripr"   r*   r   r   rx   )rP   rs   r   r   Zall_ignored_typesr   Zraw_annotationsignored_namesvar_namevalueZsuggested_nameZann_nameZann_typerE   rE   rF   rr     s   









rr   rN   c                 C  sT   d| v rd S d }|D ]}t |dt}|tur nq
|d u r(ddd}|| d< d S d S )	N__hash__rA   r   r8   intc                 S  s   t | jt t| j  S rb   )hashrD   r|   r   valuesr   rE   rE   rF   	hash_func  s   z(set_default_hash_func.<locals>.hash_func)rA   r   r8   r   )rx   r
   )rP   rN   Zbase_hash_funcr   r   rE   rE   rF   ru   u  s   
ru   r   type[BaseModel]r   r   rp   c           	      C  sl   t | }t| ||||d\}}|| _| j| |D ]}| j|d}|dur3|jtur3t	| ||j qdS )a.  Collect and set `cls.model_fields` and `cls.__class_vars__`.

    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_mapN)
r%   r    r   r^   r   r_   popr   r
   setattr)	r   rN   r   rp   r   fieldsr   r4   r   rE   rE   rF   r     s   r   )ro   rM   r5   ro   rU   dict[str, Any] | Nonec             
   C  s  t | }t|||}tt|jdd|dd}|jr t| | dS z| | |}W n! tyI }	 z|r3 t| |d|	j	 d W Y d}	~	dS d}	~	ww |
| }
||}tt|}t|ret| | dS || _t|}t||
| _t||
| _d| _tdt| j| j|| _dS )	a  Finish building a model class.

    This logic must be called after class has been created since validation functions must be bound
    and `get_type_hints` requires a class object.

    Args:
        cls: BaseModel or dataclass.
        cls_name: The model or dataclass name.
        config_wrapper: The config wrapper instance.
        raise_errors: Whether to raise errors.
        types_namespace: Optional extra namespace to look for types in.

    Returns:
        `True` if the model is successfully completed, else `False`.

    Raises:
        PydanticUndefinedAnnotation: If `PydanticUndefinedAnnotation` occurs in`__get_pydantic_core_schema__`
            and `raise_errors=True`.
    F)Zfrom_dunder_get_core_schemaunpack)Zref_moder:   NT__signature__)r%   r#   r(   r   Zgenerate_schemaZdefer_buildr'   Z__get_pydantic_core_schema__r   r   core_configZcollect_definitionsr   r   r   r   r   r   r   r   Z__pydantic_serializer__r   r,   generate_model_signaturery   r   r   )r   rM   r   ro   rp   r   Z
gen_schemahandlerZschemaer   Zsimplified_core_schemarE   rE   rF   r     sL   



r   initCallable[..., None]r   r   r/   c                 C  s  ddl m}m}m} ddlm} || j }i }d}	d}
||ddD ]}|jdkr0|j	t
d}|j|ju r9|}	q#|||j< q#|	r|j}| D ]G\}}t|jtrV|j}n|}||v s`||v raqHt|sq|rnt|rn|}nd	}
qH| rwi nd
|jddi}|||jfd| i|||< qH|jdkrd	}
|	r|
rd|jfd|jfg}dd |D |krd}n|	j}||v r|d7 }||v s|	j	|d||< |t| ddS )zGenerate signature for model based on its fields.

    Args:
        init: The class init.
        fields: The model fields.
        config_wrapper: The config wrapper instance.

    Returns:
        The model signature.
    r   )	Parameterr/   	signature)isliceNFr   r   )
annotationTr   )Zcall_default_factoryr   ZallowZ__pydantic_self__datac                 S  s   g | ]}|j |jfqS rE   )r   kind)rd   prE   rE   rF   rh   2  s    z,generate_model_signature.<locals>.<listcomp>
extra_datar   )r   )r`   return_annotation)inspectr   r/   r   	itertoolsr   r`   r   r   replacer   r   VAR_KEYWORDr   Zpopulate_by_namer   r<   aliasr5   r-   Zis_requiredr   KEYWORD_ONLYZrebuild_annotationextraPOSITIONAL_OR_KEYWORDr   )r   r   r   r   r/   r   r   Zpresent_paramsZmerged_paramsZvar_kwZ
use_var_kwparamZallow_names
field_namefield
param_namerV   Zdefault_model_signatureZvar_kw_namerE   rE   rF   r     s`   

r   c                   @  s   e Zd ZdS )_PydanticWeakRefN)rG   rH   rI   rE   rE   rE   rF   r   A  s    r   dc              	   C  sR   | du rdS i }|   D ]\}}zt|}W n ty!   |}Y nw |||< q|S )aX  Takes an input dictionary, and produces a new value that (invertibly) replaces the values with weakrefs.

    We can't just use a WeakValueDictionary because many types (including int, str, etc.) can't be stored as values
    in a WeakValueDictionary.

    The `unpack_lenient_weakvaluedict` function can be used to reverse this operation.
    N)r   r   r~   )r   resultr4   r6   proxyrE   rE   rF   r   E  s   
r   c                 C  sP   | du rdS i }|   D ]\}}t|tr!| }|dur |||< q|||< q|S )zAInverts the transform performed by `build_lenient_weakvaluedict`.N)r   r<   r   )r   r   r4   r6   rE   rE   rF   r   Y  s   

r   )rA   r1   r   r   r8   r9   )
rP   rQ   rs   rO   r   r   r   r   r8   r   )rP   rQ   rN   rO   r8   r9   )
r   r   rN   rO   r   r   rp   rQ   r8   r9   )r   r   rM   r5   r   r   ro   rU   rp   r   r8   rU   )r   r   r   r   r   r   r8   r/   )r   r   r8   r   )_rJ   
__future__r   Z_annotationsr   r=   weakrefabcr   r   r   typesr   r   r   r   r	   Zpydantic_corer
   r   r   Ztyping_extensionsr   r   errorsr   r   r   r   r   r   r   r   _configr   Z_core_utilsr   r   r   Z_decoratorsr   r   r   Z_discriminated_unionr   _fieldsr    r!   r"   Z_generate_schemar#   Z	_genericsr$   r%   Z_mock_val_serr&   r'   Z_schema_generation_sharedr(   Z_typing_extrar)   r*   r+   _utilsr,   r-   Z_validate_callr.   r   r   r/   rw   r1   r   r   r   r   r2   r   r7   __setattr__r   r   r3   rL   r[   rr   ru   r   r   r   ReferenceTyper   r   r   rE   rE   rE   rF   <module>   sj    	 
5

m
#
JP
