o
    @jq                     @  s  d Z ddlmZ ddlZddlZddlZddlZddlZddl	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ZddlmZmZ dd	lmZmZ d
dlmZ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) ddl*m+Z+m,Z,m-Z- ddl.m/Z/ ddl0m1Z1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z=m>Z>m?Z?m@Z@mAZAmBZB ddlCmDZDmEZE ddlFmGZG ejHrd
dlImJZK d
dlImLZLmMZM d
dlImNZO d
dlPmQZQ ne"ZReS ZKeS ZOeSjTZUG dd  d eVZWd!d"ddd'd(ZXed)eKeOeXfd*G d+d, d,eZYded1d2ZZdfd8d9Z[dgd?d@Z\dhdCdDZ]didEdFZ^djdJdKZ_d)ddLdkdTdUZ`dldVdWZaG dXdY dYZbG dZd[ d[Zcdmd]d^Zddmd_d`ZeeddadndbdcZfdS )oz"Private logic for creating models.    )annotationsN)ABCMeta)	lru_cachepartial)FunctionType)AnyCallableGenericLiteralNoReturn)PydanticUndefinedSchemaSerializer)dataclass_transform
deprecated   )PydanticUndefinedAnnotationPydanticUserError)create_schema_validator)GenericBeforeBaseModelWarningPydanticDeprecatedSince20   )ConfigWrapper)DecoratorInfosPydanticDescriptorProxyget_attribute_from_basesunwrap_wrapped_function)collect_model_fieldsis_valid_field_nameis_valid_privateattr_name)GenerateSchema)PydanticGenericMetadataget_model_typevars_map)import_cached_base_modelimport_cached_field_info)set_model_mocks)CallbackGetCoreSchemaHandler)generate_pydantic_signature)_make_forward_refeval_type_backportis_annotatedis_classvarmerge_cls_and_parent_nsparent_frame_namespace)ClassAttributeSafeGetItemProxy)ValidateCallWrapper)Field)	FieldInfoModelPrivateAttr)PrivateAttr)	BaseModelc                      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warndecorator_infodecorator_reprsuper__setitem__)selfr6   r8   existing	__class__ u/var/www/www-root/data/www/ai-bot.pdev.uz/venv/lib/python3.10/site-packages/pydantic/_internal/_model_construction.pyrD   ?   s   z_ModelNamespaceDict.__setitem__)r6   r7   r8   r9   r:   r;   )__name__
__module____qualname____doc__rD   __classcell__rI   rI   rG   rJ   r5   :   s    r5   FinitrQ   Literal[False]r:   r   c                 C     dS )zOnly for typing purposes. Used as default value of `__pydantic_fields_set__`,
    `__pydantic_extra__`, `__pydantic_private__`, so they could be ignored when
    synthesizing the `__init__` signature.
    NrI   rP   rI   rI   rJ   NoInitFieldG       rT   T)kw_only_defaultfield_specifiersc                      s   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"dd#d0d%d&Zd1 fd(d)Z  ZS )2ModelMetaclassNTcls_namer7   basestuple[type[Any], ...]	namespacedict[str, Any]__pydantic_generic_metadata__PydanticGenericMetadata | None#__pydantic_reset_parent_namespace__bool_create_model_module
str | Nonekwargsr   r:   typec                   s|  |r|  |\}}	}
t|||}|j|d< t||j|	|}|s#|
r<t||  dur8d3 fd	d
}||d< nt|d< |	|d< i |
||d< t j	| |||fi |}t
 }|j}t|v rr|t||k rrtjtddd t|jdd |_|j|ju rdnd|_t||_|r||_nt|di ddt|ddpr)r)tfddD s)ddlm} tfddD }|v r|vrddd |D }|j  d| d|j  d | d!}t!|| }dd"d |D }d#| d$}d%| d&}t|vr%dd'd |D |g }|d(|j  d)| d*7 }t!|ddd+|_d|_"|# D ]\}}|$|| q7|rLt%t& |_'t|d,d}t(|t)r\t*|}t+||}t,|||| |j-rvd-|vrvt.|| t/|||d||d. d/d0 |jj0# D |_1t2| t||j3di | |S d1D ]	}|4|d q|d2i 5  t j	| |||fi |S )4a  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.
            _create_model_module: The module of the class to be created, if created by `create_model`.
            **kwargs: Catch-all for any other keyword arguments.

        Returns:
            The new class created by the metaclass.
        model_configNrE   r4   contextr   r:   r;   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)rE   rg   )original_model_post_initrI   rJ   wrapped_model_post_init{   s   
z7ModelMetaclass.__new__.<locals>.wrapped_model_post_initmodel_post_init__class_vars____private_attributes__zClasses should inherit from `BaseModel` before generic classes (e.g. `typing.Generic[T]`) for pydantic generics to work properly.r   
stacklevel__pydantic_base_init__Fr^   
parametersrI   __parameters__c                 3  s    | ]}| v V  qd S NrI   .0x)rq   rI   rJ   	<genexpr>   s    z)ModelMetaclass.__new__.<locals>.<genexpr>)RootModelRootTypec                 3  s    | ]	}| vr|V  qd S rs   rI   rt   )parent_parametersrI   rJ   rw      s    z, c                 S     g | ]}|j qS rI   rK   rt   rI   rI   rJ   
<listcomp>       z*ModelMetaclass.__new__.<locals>.<listcomp>zS is a subclass of `RootModel`, but does not include the generic type identifier(s) zL in its parameters. You should parametrize RootModel directly, e.g., `class z(RootModel[z	]): ...`.c                 S  s   g | ]}t |qS rI   )r7   rt   rI   rI   rJ   r|      s    ztyping.Generic[]zJAll parameters must be present on typing.Generic; you should inherit from .c                 S  rz   rI   r{   rt   rI   rI   rJ   r|      r}   z- Note: `typing.Generic` must go last: `class (z): ...`))originargsrq   __pydantic_parent_namespace____hash__)raise_errorstypes_namespacecreate_model_modulec                 S  s   i | ]\}}||j qS rI   )info)ru   r6   r8   rI   rI   rJ   
<dictcomp>   s    z*ModelMetaclass.__new__.<locals>.<dictcomp>)__pydantic_fields_set____pydantic_extra____pydantic_private____annotations__rE   r4   rg   r   r:   r;   )6_collect_bases_datar   	for_modelconfig_dictinspect_namespaceignored_typesget_model_post_initrh   rC   __new__r"   __mro__r	   indexr?   r@   r   getattr__init____pydantic_custom_init__rk   __pydantic_post_init__r   build__pydantic_decorators__r^   r=   all
root_modelrx   tuplejoinrK   	TypeError__pydantic_complete__items__set_name__build_lenient_weakvaluedictr,   r   r>   dictunpack_lenient_weakvaluedictr+   set_model_fieldsfrozenset_default_hash_funccomplete_model_classcomputed_fieldsmodel_computed_fieldsset_deprecated_descriptors__pydantic_init_subclass__popclear)mcsrY   rZ   r\   r^   r`   rb   rd   base_field_names
class_varsbase_private_attributesconfig_wrapperprivate_attributesrj   clsr4   mrorx   missing_parametersparameters_strerror_messagecombined_parametersgeneric_type_label	bases_strnameobjparent_namespacer   instance_slotrG   )ri   rq   ry   rJ   r   S   s   



$


zModelMetaclass.__new__itemc                 C  s(   | j d}|r||v r|| S t|)zNThis is necessary to keep attribute access working for class attribute access.rm   )__dict__r=   AttributeError)rE   r   r   rI   rI   rJ   __getattr__  s   zModelMetaclass.__getattr__r   dict[str, object]c                 O  s   t  S rs   )r5   )r   r   rd   rI   rI   rJ   __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
        __pydantic_validator__)hasattrrC   __instancecheck__)rE   r   rG   rI   rJ   r     s   z ModelMetaclass.__instancecheck__6tuple[set[str], set[str], dict[str, ModelPrivateAttr]]c                 C  sj   t  }t }t }i }| D ]"}t||r/||ur/|t|di   ||j ||j q|||fS )Nmodel_fields)r"   set
issubclassupdater   keysrl   rm   )rZ   r4   field_namesr   r   baserI   rI   rJ   r     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@   r   r   rE   rI   rI   rJ   
__fields__"  s   zModelMetaclass.__fields__	list[str]c                   s$   t t  }d|v r|d |S )Nr   )listrC   __dir__remove)rE   
attributesrG   rI   rJ   r   *  s   
zModelMetaclass.__dir__)NTN)rY   r7   rZ   r[   r\   r]   r^   r_   r`   ra   rb   rc   rd   r   r:   re   )r   r7   r:   r   )r   r   rd   r   r:   r   )r   r   r:   ra   )rZ   r[   r:   r   )r:   r   )r:   r   )rK   rL   rM   r   typingTYPE_CHECKINGr   classmethodr   r   staticmethodr   propertyr   r   r   rO   rI   rI   rG   rJ   rX   Q   s"     ,

rX   rE   r4   rg   r;   c                C  sT   t | dddu r(i }| j D ]\}}| }|tur|||< qt| d| dS 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.
    r   N)r   rm   r   get_defaultr   object_setattr)rE   rg   pydantic_privater   private_attrdefaultrI   rI   rJ   rh   1  s   	rh   r\   r]   rZ   r[   Callable[..., Any] | Nonec                 C  s2   d| v r| d S t  }t|d}||jur|S dS )zaGet the `model_post_init` method from the namespace or the class bases, or `None` if not defined.rk   N)r"   r   rk   )r\   rZ   r4   rk   rI   rI   rJ   r   C  s   

r   r   base_class_varsset[str]base_class_fieldsdict[str, ModelPrivateAttr]c              
     s  ddl m m} t }|t  }i }| di }d|v s d| v r$tdt }	t| 	 D ]\}
}|
dks9|
dkr:q-t
|trS|j| d krSd	| v rS|j| d	 rSq-t
||s^|jjd
krd|	|
 q-t
| r|
drvtd|
dt|
rtdd|
 d|
d|||
< | |
= q-t
||rt|
s|
dpd}td|d|
d|
drq-t|
r|
|vst||
 s||d||
< | |
= q-|
|v rq-|
|vr|
|v rtd|
ddd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
|trWtd}|durWztt|dd d!|j|jd"}W n ttfyV   Y nw t|rzt !|^}}t" fd#d$|D d}|durz|||< q| ||< 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.
    r   )r2   r3   r   __root__zUTo define root models, use `pydantic.RootModel` rather than a field called '__root__'rf   r   rL   rM   	functools__zXPrivate attributes must not use dunder names; use a single underscore prefix instead of r   zJPrivate attributes must not use valid field names; use sunder names, e.g. _z instead of 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']`.NFT)is_argumentis_class)globalnslocalnsc                 3  s    | ]
}t | r|V  qd S rs   )r>   )ru   r8   r2   rI   rJ   rw     s    z$inspect_namespace.<locals>.<genexpr>)#fieldsr2   r3   r#   default_ignored_typesr=   r   r   r   r   r>   re   rL   rM   
startswithrH   add	NameErrorr   lstripr   r*   r   r   r7   sys	_getframer(   r'   	f_globalsf_localsr)   typing_extensionsget_argsnext)r\   r   r   r   r3   r1   all_ignored_typesr   raw_annotationsignored_namesvar_namevaluesuggested_nameann_nameann_typeframer   metadatar   rI   r   rJ   r   O  s   















r   r   type[BaseModel]c                 C  s@   t |d}t| }|d tjhv st|dd |jkr|| _d S d S )Nr   __code__)r   make_hash_funcr9   r   r   r  )r   rZ   base_hash_funcnew_hash_funcrI   rI   rJ   r     s
   
 
r   c                   s0   | j rtj| j   ndd  d	 fdd}|S )
Nc                 S  rS   )Nr   rI   )r   rI   rI   rJ   <lambda>  rU   z make_hash_func.<locals>.<lambda>rE   r   r:   intc                   s6   zt  | jW S  ty   t  t| j Y S w rs   )hashr   KeyErrorr.   r   getterrI   rJ   	hash_func  s
   z!make_hash_func.<locals>.hash_func)rE   r   r:   r  )r   operator
itemgetterr   )r   r  rI   r  rJ   r    s   
r  r   r   r   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   rl   r   rm   r   r   r   setattr)	r   rZ   r   r   r   r   r   r6   r  rI   rI   rJ   r     s   r   )r   r   rY   r7   r   ra   dict[str, Any] | Noner   rc   c             
   C  s6  t | }t|||}tt|jdd|dd}|jr%d|jv r%t| | dS z| | |}	W n! t	yN }
 z|r8 t| |d|
j
 d W Y d}
~
dS d}
~
ww || }z||	}	W n |jyk   t| | Y dS w |	| _t|	| |pv| j| j|r|dnd	||j| _t|	|| _d
| _tdt| j| j|d| _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.
        create_model_module: The module of the class to be created, if created by `create_model`.

    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)from_dunder_get_core_schemaunpack)ref_modemodelr<   Ncreate_modelr4   T__signature__)rQ   r   r   )r!   r   r%   r   generate_schemadefer_buildexperimental_defer_build_moder$   __get_pydantic_core_schema__r   r   core_configclean_schemaCollectedInvalid__pydantic_core_schema__r   rL   rM   plugin_settingsr   r   __pydantic_serializer__r   r-   r&   r   r   r(  )r   rY   r   r   r   r   r   
gen_schemahandlerschemaer-  rI   rI   rJ   r     s^   



	r   c                 C  s   | j  D ]\}}|j }dur t|}|| | t| || q| j D ]%\}}|j }durKtt|j	dsKt||j	}|| | t| || q&dS )z8Set data descriptors on the class for deprecated fields.N__deprecated__)
r   r   deprecation_message_DeprecatedFieldDescriptorr   r!  r   r   r   wrapped_property)r   field
field_infomsgdesccomputed_field_inforI   rI   rJ   r   g  s   r   c                   @  sF   e Zd ZU dZded< ddd
dZdddZddddZd ddZdS )!r9  aM  Data descriptor used to emit a runtime deprecation warning before accessing a deprecated field.

    Attributes:
        msg: The deprecation message to be emitted.
        wrapped_property: The property instance if the deprecated field is a computed field, or `None`.
        field_name: The name of the field being deprecated.
    r7   
field_nameNr=  r:  property | Noner:   r;   c                 C  s   || _ || _d S rs   )r=  r:  )rE   r=  r:  rI   rI   rJ   r     s   
z#_DeprecatedFieldDescriptor.__init__r   r  r   c                 C  s
   || _ d S rs   )r@  )rE   r   r   rI   rI   rJ   r        
z'_DeprecatedFieldDescriptor.__set_name__r   BaseModel | Noneobj_typetype[BaseModel] | Noner   c                 C  sJ   |d u r	t | jtj| jtjdd | jd ur| j||S |j	| j S )Nr   rn   )
r   r@  r?   r@   r=  builtinsDeprecationWarningr:  __get__r   )rE   r   rD  rI   rI   rJ   rH    s   

z"_DeprecatedFieldDescriptor.__get__r  r   c                 C  s
   t | jrs   )r   r@  )rE   r   r  rI   rI   rJ   __set__  rB  z"_DeprecatedFieldDescriptor.__set__rs   )r=  r7   r:  rA  r:   r;   )r   r  r   r7   r:   r;   )r   rC  rD  rE  r:   r   )r   r   r  r   r:   r   )	rK   rL   rM   rN   r   r   r   rH  rI  rI   rI   rI   rJ   r9  z  s   
 
r9  c                   @  s.   e Zd ZdZdddZdddZdd
dZdS )_PydanticWeakRefa  Wrapper for `weakref.ref` that enables `pickle` serialization.

    Cloudpickle fails to serialize `weakref.ref` objects due to an arcane error related
    to abstract base classes (`abc.ABC`). This class works around the issue by wrapping
    `weakref.ref` instead of subclassing it.

    See https://github.com/pydantic/pydantic/issues/6763 for context.

    Semantics:
        - If not pickled, behaves the same as a `weakref.ref`.
        - If pickled along with the referenced object, the same `weakref.ref` behavior
          will be maintained between them after unpickling.
        - If pickled without the referenced object, after unpickling the underlying
          reference will be cleared (`__call__` will always return `None`).
    r   r   c                 C  s"   |d u r	d | _ d S t|| _ d S rs   )_wrweakrefref)rE   r   rI   rI   rJ   r     s   
z_PydanticWeakRef.__init__r:   c                 C  s   | j d u rd S |   S rs   )rK  r   rI   rI   rJ   __call__  s   
z_PydanticWeakRef.__call__4tuple[Callable, tuple[weakref.ReferenceType | None]]c                 C  s   t |  ffS rs   )rJ  r   rI   rI   rJ   
__reduce__  s   z_PydanticWeakRef.__reduce__N)r   r   )r:   r   )r:   rO  )rK   rL   rM   rN   r   rN  rP  rI   rI   rI   rJ   rJ    s
    

rJ  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   rJ  r   )rQ  resultr6   r8   proxyrI   rI   rJ   r     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>   rJ  )rQ  rR  r6   r8   rI   rI   rJ   r     s   

r   )maxsizec                  C  s   ddl m}  ttttt| tfS )Nr   ComputedFieldInfo)r   rV  r   r   r   r   r   r/   rU  rI   rI   rJ   r     s   r   )rQ   rR   r:   r   r   )r\   r]   rZ   r[   r:   r   )
r\   r]   r   r[   r   r   r   r   r:   r   )r   r  rZ   r[   r:   r;   )r   r  r:   r   )
r   r  rZ   r[   r   r   r   r]   r:   r;   )r   r  rY   r7   r   r   r   ra   r   r"  r   rc   r:   ra   )r   r  r:   r;   )rQ  r"  r:   r"  )r:   r[   )grN   
__future__r   _annotationsrF  r  r  r   r?   rL  abcr   r   r   r   typesr   r   r   r	   r
   r   r  pydantic_corer   r   r   r   errorsr   r   plugin._schema_validatorr   r   r   _configr   _decoratorsr   r   r   r   _fieldsr   r   r   _generate_schemar   	_genericsr    r!   _import_utilsr"   r#   _mock_val_serr$   _schema_generation_sharedr%   
_signaturer&   _typing_extrar'   r(   r)   r*   r+   r,   _utilsr-   r.   _validate_callr/   r   r   r0   PydanticModelFieldr1   r2   r3   PydanticModelPrivateAttrmainr4   rG  r9   __setattr__r   r   r5   rT   rX   rh   r   r   r   r  r   r   r   r9  rJ  r   r   r   rI   rI   rI   rJ   <module>   s|     
 
`

 
	

#
U#
#
