
    h-i!j                       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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# 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/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5m6Z6m7Z7 ddl8m9Z9 ddl:m;Z; ejx                  rddl=m>Z> d
dl?m@ZA d
dl?mBZBmCZC d
dlDmEZE n	eZF eG       ZAeGj                  ZI G d deJ      ZK edeAf        G d! d"e             ZLd0d#ZMd1d$ZN	 	 	 	 	 	 	 	 	 	 d2d%ZOd3d&ZP	 	 	 	 	 	 	 	 	 	 d4d'ZQddd(	 	 	 	 	 	 	 	 	 	 	 	 	 d5d)ZR	 	 	 	 	 	 	 	 d6d*ZS G d+ d,      ZTd7d-ZUd7d.ZVd8d/ZWy)9z"Private logic for creating models.    )annotationsN)ABCMeta)partial)FunctionType)AnyCallableGenericMapping)PydanticUndefinedSchemaSerializer)dataclass_transform
deprecated   )PydanticUndefinedAnnotationPydanticUserError)create_schema_validator)GenericBeforeBaseModelWarningPydanticDeprecatedSince20   )ConfigWrapper)DecoratorInfosPydanticDescriptorProxyget_attribute_from_bases)collect_model_fieldsis_valid_field_nameis_valid_privateattr_name)GenerateSchemagenerate_pydantic_signature)PydanticGenericMetadataget_model_typevars_map)
MockValSerset_model_mocks)CallbackGetCoreSchemaHandler)get_cls_types_namespaceis_annotatedis_classvarparent_frame_namespace)ClassAttribute)ValidateCallWrapper)	Signature)Field)	FieldInfoModelPrivateAttr	BaseModelc                  $     e Zd ZdZd fdZ xZS )_ModelNamespaceDictz{A dictionary subclass that intercepts attribute setting on model classes and
    warns about overriding of decorators.
    c                    | j                  |d       }|rD||ur@t        |t              r0t        j                  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__)selfkvexisting	__class__s       eD:\DhanshreeandTeamAI\Github\ai_code\venv\Lib\site-packages\pydantic/_internal/_model_construction.pyr;   z_ModelNamespaceDict.__setitem__2   sc    D))jCZ.[MMAaS B8CZCZCiCiBjjuvww"1a((    )r=   strr>   objectreturnNone)__name__
__module____qualname____doc__r;   __classcell__r@   s   @rA   r1   r1   -   s    ) )rB   r1   T)kw_only_defaultfield_specifiersc                       e Zd Z	 	 	 d		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d
 fdZej
                  sddZedd       Zd fdZ	e
dd       Ze ede      dd              Z xZS )ModelMetaclassc                t   |r| j                  |      \  }}	}
t        j                  |||      }|j                  |d<   t	        ||j
                  |	|      }|r#t        ||      dfd}||d<   n	t        |d<   |	|d<   i |
||d<   |j                  rt        ||       t        | ,  | |||fi |}ddlm} |j                  }t        |v rG|j!                  t              |j!                  |      k  r t#        j$                  t'        d	      d
       t)        |j*                  dd       |_        |j.                  |j.                  u rdnd|_        t3        j4                  |      |_        |r||_        nt)        |di       j;                  dd      t)        |dd      xs rrt=        fdD              st?        fdD              z   }djA                  |D cg c]  }tC        |       c}      }d| d}d| d}t        |vrCdjA                  |D cg c]  }|jD                   c}|gz         }|d|jD                   d| dz  }tG        |      ddd|_        d|_$        |jK                         D ]  \  }}|jM                  ||        |rtO        tQ                     |_)        t)        |dd      }tU        |tV              rtY        |      }t[        ||      }t]        ||||       t_        |||d||       t        ||  di | |S t        | ,  | |||fi |S c c}w c c}w )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.
            _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_configNc                0    t        | |        | |       y)zWe need to both initialize private attributes and call the user-defined model_post_init
                        method.
                        N)init_private_attributes)r<   _ModelMetaclass__contextoriginal_model_post_inits     rA   wrapped_model_post_initz7ModelMetaclass.__new__.<locals>.wrapped_model_post_initd   s     0i@0yArB   model_post_init__class_vars____private_attributes__r   r.   zClasses should inherit from `BaseModel` before generic classes (e.g. `typing.Generic[T]`) for pydantic generics to work properly.)
stacklevel__pydantic_base_init__F__pydantic_generic_metadata__
parameters __parameters__c              3  &   K   | ]  }|v  
 y wNr_   ).0xr^   s     rA   	<genexpr>z)ModelMetaclass.__new__.<locals>.<genexpr>   s     ?kYjTUZYjs   c              3  ,   K   | ]  }|vs|  y wrb   r_   )rc   rd   parent_parameterss     rA   re   z)ModelMetaclass.__new__.<locals>.<genexpr>   s     Cxz!]^fw]wAzs   	z, ztyping.Generic[]zJAll parameters must be present on typing.Generic; you should inherit from .z- Note: `typing.Generic` must go last: `class (z): ...`))originargsr^   __pydantic_parent_namespace__)raise_errorstypes_namespacecreate_model_module)r<   r/   rU   r   rE   rF   )1_collect_bases_datar   	for_modelconfig_dictinspect_namespaceignored_typesget_model_post_initrT   frozenset_default_hash_funcr:   __new__mainr/   __mro__r	   indexr6   r7   r   getattr__init____pydantic_custom_init__rX   __pydantic_post_init__r   build__pydantic_decorators__r]   r4   alltuplejoinrC   rG   	TypeError__pydantic_complete__items__set_name__build_lenient_weakvaluedictr'   rm   r5   dictunpack_lenient_weakvaluedictr$   set_model_fieldscomplete_model_class__pydantic_init_subclass__)mcscls_namebases	namespacer]   #__pydantic_reset_parent_namespace___create_model_modulekwargsbase_field_names
class_varsbase_private_attributesconfig_wrapperprivate_attributesrW   clsr/   mrocombined_parametersrd   parameters_strgeneric_type_labelerror_message	bases_strnameobjparent_namespacero   rV   r^   rg   r@   s                              @@@rA   ry   zModelMetaclass.__new__<   s   6 DGD[D[\aDbAj*A*44UIvNN(6(B(BIn%!2>77EU" "+>y%+P(+7B 4KI/03JI/0*4I&'2c5L2cPb2cI./$$%i7#(7?3%#]V\#]C(++C#~#))G"4syy7K"K1B  ! 07s||E]_d/e+eC(141D1D	HaHa1agxC&*8*>*>s*CC' -4Q1$+C1PRT$U$Y$YZfhj$k!$S*:DAVEV
"3C?kYj?k<k*;eCxzCx>x*x'%)YY@S/T@S1A@S/T%UN+:>:J!)L&44F3GqJ " e+
 %)II5.I5aqzz5.IM_L`.`$a	%KCLL>YZ[dZeemn $M22 #",51 ).C% 0557	c  d+ 8 34OPfPh4i1&s,KTR*D1#?@P#Q 5c;KLOS%I " /$8 #s6@@J 7?3%MfMMk 0U /Js   (L0$L5c                    | j                   j                  d      }|r	||v r||   S |dk(  r;t        | dd      }t        |t              r|j                         }|t        | d      S t        |      )zNThis is necessary to keep attribute access working for class attribute access.rZ   __pydantic_core_schema____pydantic_validator__N)__dict__r4   r}   r5   r!   rebuildAttributeError)r<   itemr   maybe_mock_validatorrebuilt_validators        rA   __getattr__zModelMetaclass.__getattr__   s    !%!2!23K!L!d.@&@)$//11'.t5Mt'T$2J?(<(D(D(F%(4&t-GHH &&rB   c                    t               S rb   )r1   )r   rl   r   s      rA   __prepare__zModelMetaclass.__prepare__   s    "$$rB   c                >    t        |d      xr t        | 	  |      S )zsAvoid calling ABC _abc_subclasscheck unless we're pretty sure.

        See #3829 and python/cpython#92810
        r   )hasattrr:   __instancecheck__)r<   instancer@   s     rA   r   z ModelMetaclass.__instancecheck__   s#    
 x!9:buw?XYa?bbrB   c                6   ddl m} t               }t               }i }| D ]t  }t        ||      s||us|j	                  t        |di       j                                |j	                  |j                         |j	                  |j                         v |||fS )Nr   r.   model_fields)	rz   r/   set
issubclassupdater}   keysrY   rZ   )r   r/   field_namesr   r   bases         rA   rq   z"ModelMetaclass._collect_bases_data   s    $ #"u
:<D$	*t9/D""74#D#I#I#KL!!$"5"56"))$*E*EF  J(:::rB   EThe `__fields__` attribute is deprecated, use `model_fields` instead.)categoryc                N    t        j                  dt               | j                  S )Nr   )r6   r7   DeprecationWarningr   r<   s    rA   
__fields__zModelMetaclass.__fields__   s     
 	]_qr   rB   )NTN)r   rC   r   tuple[type[Any], ...]r   dict[str, Any]r]   zPydanticGenericMetadata | Noner   boolr   
str | Noner   r   rE   type)r   rC   rE   r   )rl   r   r   r   rE   zMapping[str, object])r   r   rE   r   )r   r   rE   z6tuple[set[str], set[str], dict[str, ModelPrivateAttr]])rE   dict[str, FieldInfo])rG   rH   rI   ry   typingTYPE_CHECKINGr   classmethodr   r   staticmethodrq   propertyr   r   r   rK   rL   s   @rA   rP   rP   :   s     IM48+/ININ %IN "	IN
 (FIN .2IN )IN IN 
INV 	' % %c ; ; OZs! !rB   rP   c                    t        | dd      Pi }| j                  j                         D ]#  \  }}|j                         }|t        us|||<   % t        | d|       yy)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.
    __pydantic_private__N)r}   rZ   r   get_defaultr   object_setattr)r<   	__contextpydantic_privater   private_attrdefaults         rA   rT   rT      sp     t+T2:"&"="="C"C"ED,"..0G//)0 & #F 	t35EF ;rB   c                Z    d| v r| d   S ddl m} t        |d      }||j                  ur|S y)zaGet the `model_post_init` method from the namespace or the class bases, or `None` if not defined.rX   r   r.   N)rz   r/   r   rX   )r   r   r/   rX   s       rA   rv   rv     s?    I%*++ .u6GHOi777 8rB   c           
     ^   ddl m}mm} |t	               z   }i }| j                  di       }d|v sd| v rt        d      t               }	t        | j                               D ]  \  }
}|
dk(  rt        |t              r1|j                  | d   k(  r|j                  j                  | d         rNt        ||      s|j                  j                  d	k(  r|	j!                  |
       t        |      rI|
j                  d
      rt#        d|
d      t%        |
      rt#        dd|
z   d|
d      |||
<   | |
= t        ||      r2t%        |
      s'|
j'                  d      xs d}t#        d|d|
d      |
j                  d
      r+t)        |
      r%|
|vst+        ||
         rJ ||      ||
<   | |
= [|
|v ra|
|vsg|
|v rt-        d|
dd      t        ||      rt-        d|
dd      t-        d|
 d|d|
 dd       |j                         D ]  \  }}t)        |      s||vs||	vst+        |      r(||vs-t/        |dd      d	k7  s>t1        |      r4t3        j4                  |      ^}}t7        fd|D        d      }||||<   } |       ||<    |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   )r,   r-   PrivateAttr__annotations____root__zUTo define root models, use `pydantic.RootModel` rather than a field called '__root__'rR   rH   rI   	functools__zXPrivate attributes must not use dunder names; use a single underscore prefix instead of ri   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']`.Nc              3  <   K   | ]  }t        |      s|  y wrb   )r5   )rc   r>   r-   s     rA   re   z$inspect_namespace.<locals>.<genexpr>  s     $\1JqJZ<[Qs   )fieldsr,   r-   r   default_ignored_typesr4   r   r   listr   r5   r   rH   rI   
startswithr@   add	NameErrorr   lstripr   r&   r   r}   r%   typing_extensionsget_argsnext)r   ru   base_class_varsbase_class_fieldsr,   r   all_ignored_typesr   raw_annotationsignored_namesvar_namevaluesuggested_nameann_nameann_typer   metadatar   r-   s                     @rA   rt   rt     sG   4 BA%(=(??68mm$5r:O_$
i(?opp!eM	 12%~%ud#  Il$;;""--i.GH 01U__5O5OS^5^h'/0""4(BBJQP  %X.//2X~.@XLXY[  ,1x((#y)2Eh2O%__S1?ZN,/|H<qJ 
   &&x0.k/RZB[6\/:5/I"8,h'(_,,,'XL )] ^1 
 E9-'XL(CDKk  (?zUI V,,4: 6jk :	 k 3x .335(%h/ 22-) 11,5DH%099(CH#$\$\^bc+3?&x0+6=x( 6" rB   c                b    d| v ry t        |d      }|d t        j                  hv r
dd}|| d<   y y )N__hash__c                    t        | j                        t        t        | j                  j	                                     z   S rb   )hashr@   r   r   valuesr   s    rA   	hash_funcz(set_default_hash_func.<locals>.hash_func  s-    '$uT]]5I5I5K/L*MMMrB   )r<   r   rE   int)r   rD   r   )r   r   base_hash_funcr   s       rA   rx   rx     sA    Y-eZ@N$00	N !*	* 1rB   c                $   t        |       }t        | ||||      \  }}|| _        | j                  j	                  |       |D ]K  }| j
                  j                  |d      }|"|j                  t        us5t        | ||j                         M y)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   rY   r   rZ   popr   r   setattr)	r   r   r   ro   r   r   r   r=   r   s	            rA   r   r     s     *#.L-c5./htuFJCj) **..q$76G!GCEMM* rB   )rn   rp   c          	        t        |       }t        |||      }t        t        |j                  d      |d      }|j
                  rt        | |       y	 | j                  | |      }	|j                  |       }	 |j                  |	      }	|	| _        t        |	| |xs | j                  | j                   |rdnd||j"                        | _        t'        |	|      | _        d	| _        t-        d
t/        | j0                  | j2                  |            | _        y	# t        $ r(}
|r t        | |d|
j                   d       Y d}
~
yd}
~
ww xY w# |j                  $ r t        | |       Y yw xY w)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_moder3   Ncreate_modelr/   T__signature__)r    r   r#   r   generate_schemadefer_buildr"   __get_pydantic_core_schema__r   r   core_configclean_schemaCollectedInvalidr   r   rH   rI   plugin_settingsr   r   __pydantic_serializer__r   r(   generate_model_signaturer~   r   r  )r   r   r   rn   ro   rp   r   
gen_schemahandlerschemaer  s               rA   r   r     s|   : *#.LJ +
**NG !!X&11#w? !,,S1K((0 $*C !8-s~~-;&&"C #36;"GC $C '1#,,@P@PR`aC C ' X166(!}5	 && X&s*   D :E 	E EEE)(E)c                    t        | ||      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   )initr   r   s      rA   r  r    s     'tV^DDrB   c                  (    e Zd ZdZddZddZddZy)	_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`).
    c                L    |d | _         y t        j                  |      | _         y rb   )_wrweakrefref)r<   r   s     rA   r~   z_PydanticWeakRef.__init__1  s     ; DH{{3'DHrB   c                <    | j                   y | j                         S rb   )r  r   s    rA   __call__z_PydanticWeakRef.__call__9  s    8888:rB   c                    t          |        ffS rb   )r  r   s    rA   
__reduce__z_PydanticWeakRef.__reduce__?  s    $&**rB   N)r   r   )rE   r   )rE   z4tuple[Callable, tuple[weakref.ReferenceType | None]])rG   rH   rI   rJ   r~   r  r!  r_   rB   rA   r  r     s     (+rB   r  c                    | yi }| j                         D ]  \  }}	 t        |      }|||<    |S # t        $ r |}Y w xY w)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   )dresultr=   r>   proxys        rA   r   r   C  s\     	yF	1	$Q'E q	  M  	E	s   1??c                    | yi }| j                         D ]*  \  }}t        |t              r |       }| |||<   &|||<   , |S )zAInverts the transform performed by `build_lenient_weakvaluedict`.N)r   r5   r  )r#  r$  r=   r>   s       rA   r   r   W  sS    yF	1a)*A}q	F1I  MrB   c                 P    ddl m}  t        t        t        t
        t        | t        fS )Nr   ComputedFieldInfo)r   r)  r   r   r   r   r   r)   r(  s    rA   r   r   g  s&    * 	 rB   )r<   r/   r   r   rE   rF   )r   r   r   r   rE   zCallable[..., Any] | None)
r   r   ru   r   r   set[str]r   r*  rE   zdict[str, ModelPrivateAttr])r   r   r   r   rE   rF   )
r   type[BaseModel]r   r   r   r   ro   r   rE   rF   )r   r+  r   rC   r   r   rn   r   ro   dict[str, Any] | Nonerp   r   rE   r   )r  zCallable[..., None]r   r   r   r   rE   r*   )r#  r,  rE   r,  )rE   r   )XrJ   
__future__r   _annotationsr   r6   r  abcr   r   r   typesr   r   r   r	   r
   r   pydantic_corer   r   r   r   errorsr   r   plugin._schema_validatorr   r   r   _configr   _decoratorsr   r   r   _fieldsr   r   r   _generate_schemar   r   	_genericsr   r    _mock_val_serr!   r"   _schema_generation_sharedr#   _typing_extrar$   r%   r&   r'   _utilsr(   _validate_callr)   r   inspectr*   r   r+   PydanticModelFieldr,   r-   rz   r/   r   rD   __setattr__r   r   r1   rP   rT   rv   rt   rx   r   r   r  r  r   r   r   r_   rB   rA   <module>rA     s   ( 2       2 2  = = C > O " Z Z Y Y I F 6 C e e " /	!44  3##
)$ 
) T=O<QR~!W ~! S~!BG$	rr(r r  	r
 !rj*+	+!6+HU+hv+	+F &*Q	QQ "Q
 Q +Q $Q 
QhE
E';EMZEE  +  +F( rB   