o
    ¨Ýj<  ã                   @  sÒ  U 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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 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mZm Z m!Z! ddl"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z) ddl*m+Z+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 e#rµee6e$f ee7e$f B Z8de9d< ee6 ee7 B Z:de9d< ddl;m<Z< e6e=e>e7e?e@eAe!eeeejBee eCjDeEjDhZFde9d< eGeHeIeJeKe	e
ehZLde9d< dgdd „ZMdhd#d$„ZNdid(d)„ZOdjd+d,„ZPdkd.d/„ZQdld2d3„ZRe(d4ƒZSdmd8d9„ZTdnd=d>„ZUe(d?ƒZVe7d@œdodFdG„ZWG dHdI„ dIe2jXƒZYe#�r&dpdMdN„ZZnG dOdN„ dNƒZZe(dPƒZ[dqdRdS„Z\e]ƒ Z^drdWdX„Z_dsd[d\„Z`ejad]d]d^�G d_d`„ d`ƒƒZbe(dadbdc�Zce(ddƒZdG dedf„ dfe%ecedf ƒZedS )tz�Bucket of reusable internal utilities.

This should be reduced as much as possible with functions only used in one place, moved to that place.
é    )ÚannotationsN)ÚOrderedDictÚdefaultdictÚdeque)ÚCallableÚIterableÚMapping)ÚSet)Údeepcopy)Úcached_property)Ú	Parameter)Úzip_longest)ÚBuiltinFunctionTypeÚCodeTypeÚFunctionTypeÚGeneratorTypeÚ
LambdaTypeÚ
ModuleTypeÚNoneType)ÚTYPE_CHECKINGÚAnyÚGenericÚ	TypeAliasÚ	TypeGuardÚTypeVarÚoverload)ÚMISSINGÚPydanticUndefined)Ú
deprecated)ÚPydanticDeprecatedSince211é   )Ú_reprÚ_typing_extra)Úimport_cached_base_modelr   ÚMappingIntStrAnyÚAbstractSetIntStré   )Ú	BaseModelzset[type[Any]]ÚIMMUTABLE_NON_COLLECTIONS_TYPESÚBUILTIN_COLLECTIONSÚparamr   ÚreturnÚboolc                 C  s   | j tjtjfv S )aZ  Return whether the parameter accepts a positional argument.

    ```python {test="skip" lint="skip"}
    def func(a, /, b, *, c):
        pass

    params = inspect.signature(func).parameters
    can_be_positional(params['a'])
    #> True
    can_be_positional(params['b'])
    #> True
    can_be_positional(params['c'])
    #> False
    ```
    )Úkindr   ÚPOSITIONAL_ONLYÚPOSITIONAL_OR_KEYWORD)r*   © r0   úT/var/www/html/chatgpt/venv/lib/python3.10/site-packages/pydantic/_internal/_utils.pyÚcan_be_positionalH   s   r2   Úvr   c                 C  s   t | ttttttfƒS ©N)Ú
isinstanceÚlistÚtupleÚsetÚ	frozensetr   r   ©r3   r0   r0   r1   Úsequence_like[   s   r;   ÚoÚclass_or_tupleú(type[Any] | tuple[type[Any], ...] | Nonec                 C  s"   zt | |ƒW S  ty   Y dS w ©NF)r5   Ú	TypeError)r<   r=   r0   r0   r1   Úlenient_isinstance_   s
   ÿrA   Úclsc                 C  s:   zt | tƒo
t| |ƒW S  ty   t | tjƒrY dS ‚ w r?   )r5   ÚtypeÚ
issubclassr@   r"   ZWithArgsTypes)rB   r=   r0   r0   r1   Úlenient_issubclassf   s   ýrE   úTypeGuard[type[BaseModel]]c                 C  s   t ƒ }t| |ƒo| |uS )zŒReturns true if cls is a _proper_ subclass of BaseModel, and provides proper type-checking,
    unlike raw calls to lenient_issubclass.
    )r#   rE   )rB   r'   r0   r0   r1   Úis_model_classo   s   rG   Ú
identifierÚstrc                 C  s   |   ¡ o	t | ¡ S )z¦Checks that a string is a valid identifier and not a Python keyword.
    :param identifier: The identifier to test.
    :return: True if the identifier is valid.
    )ÚisidentifierÚkeywordÚ	iskeyword)rH   r0   r0   r1   Úis_valid_identifierx   s   rM   ÚKeyTypeÚmappingúdict[KeyType, Any]Úupdating_mappingsc                 G  sd   |   ¡ }|D ])}| ¡ D ]"\}}||v r*t|| tƒr*t|tƒr*t|| |ƒ||< q|||< qq|S r4   )ÚcopyÚitemsr5   ÚdictÚdeep_update)rO   rQ   Zupdated_mappingZupdating_mappingÚkr3   r0   r0   r1   rU   ƒ   s    
ürU   údict[Any, Any]ÚupdateÚNonec                 K  s   |   dd„ | ¡ D ƒ¡ d S )Nc                 S  s   i | ]\}}|d ur||“qS r4   r0   )Ú.0rV   r3   r0   r0   r1   Ú
<dictcomp>�   s    z#update_not_none.<locals>.<dictcomp>)rX   rS   )rO   rX   r0   r0   r1   Úupdate_not_noneŽ   s   r\   ÚT)Úname_factoryÚ
input_listúlist[T] | tuple[T, ...]r^   úCallable[[T], str]úlist[T]c                C  sJ   g }g }| D ]}||ƒ}||vr|  |¡ |  |¡ q||| |¡< q|S )z£Make a list unique while maintaining order.
    We update the list if another one with the same name is set
    (e.g. model validator overridden in subclass).
    )ÚappendÚindex)r_   r^   ÚresultZresult_namesr3   Zv_namer0   r0   r1   Úunique_list•   s   	
rf   c                   @  sŠ   e Zd ZdZdZd-d	d
„Zd.dd„Zd.dd„Zd/dd„Zd0dd„Z	e
d1d2d d!„ƒZed3d"d#„ƒZe
d4d$d%„ƒZed5d'd(„ƒZd6d*d+„Zd,S )7Ú
ValueItemszOClass for more convenient calculation of excluded or included fields on values.©Ú_itemsÚvaluer   rS   ú$AbstractSetIntStr | MappingIntStrAnyr+   rY   c                 C  s2   |   |¡}t|ttfƒr|  |t|ƒ¡}|| _d S r4   )Ú_coerce_itemsr5   r6   r7   Ú_normalize_indexesÚlenri   )Úselfrj   rS   r0   r0   r1   Ú__init__°   s   

zValueItems.__init__Úitemr,   c                 C  s   |   | j |¡¡S )zWCheck if item is fully excluded.

        :param item: key or index of a value
        )Úis_trueri   Úget©ro   rq   r0   r0   r1   Úis_excluded¸   s   zValueItems.is_excludedc                 C  s
   || j v S )z`Check if value is contained in self._items.

        :param item: key or index of value
        rh   rt   r0   r0   r1   Úis_included¿   s   
zValueItems.is_includedÚeú	int | strú+AbstractSetIntStr | MappingIntStrAny | Nonec                 C  s   | j  |¡}|  |¡s|S dS )z�:param e: key or index of element on value
        :return: raw values for element if self._items is dict and contain needed element
        N)ri   rs   rr   )ro   rw   rq   r0   r0   r1   Úfor_elementÆ   s   zValueItems.for_elementr$   Úv_lengthÚintúdict[int | str, Any]c           	      C  s  i }d}|  ¡ D ]F\}}t|tƒs&t|tƒs&|  |¡s&td|› d|j› �ƒ‚|dkr0|  |¡}qt|tƒs9tdƒ‚|dk rA|| n|}|  	|| 
|¡¡||< q|sS|S |  |¡rgt|ƒD ]}| |d¡ q\|S t|ƒD ]}| |i ¡}|  |¡s€|  	||¡||< qk|S )a]  :param items: dict or set of indexes which will be normalized
        :param v_length: length of sequence indexes of which will be

        >>> self._normalize_indexes({0: True, -2: True, -1: True}, 4)
        {0: True, 2: True, 3: True}
        >>> self._normalize_indexes({'__all__': True}, 4)
        {0: True, 1: True, 2: True, 3: True}
        Nz,Unexpected type of exclude value for index "z" Ú__all__z€Excluding fields from a sequence of sub-models or dicts must be performed index-wise: expected integer keys or keyword "__all__"r   .)rS   r5   r   ÚAbstractSetrr   r@   Ú	__class__Ú_coerce_valuer|   Úmergers   ÚrangeÚ
setdefault)	ro   rS   r{   Znormalized_itemsZ	all_itemsÚir3   Znormalized_iZnormalized_itemr0   r0   r1   rm   Í   s4   	

ÿ

€zValueItems._normalize_indexesFÚbaseÚoverrideÚ	intersectc                   sÎ   |   ˆ¡‰|   ˆ ¡‰ ˆdu rˆ S |  ˆ ¡sˆ du rˆS |  ˆ¡r&|r$ˆ S ˆS |r;‡fdd„ˆ D ƒ‡ fdd„ˆD ƒ }ntˆ ƒ‡ fdd„ˆD ƒ }i }|D ]}| jˆ  |¡ˆ |¡|d�}|durd|||< qL|S )aH  Merge a `base` item with an `override` item.

        Both `base` and `override` are converted to dictionaries if possible.
        Sets are converted to dictionaries with the sets entries as keys and
        Ellipsis as values.

        Each key-value pair existing in `base` is merged with `override`,
        while the rest of the key-value pairs are updated recursively with this function.

        Merging takes place based on the "union" of keys if `intersect` is
        set to `False` (default) and on the intersection of keys if
        `intersect` is set to `True`.
        Nc                   ó   g | ]}|ˆ v r|‘qS r0   r0   ©rZ   rV   )r‡   r0   r1   Ú
<listcomp>  ó    z$ValueItems.merge.<locals>.<listcomp>c                   r‰   r0   r0   rŠ   ©r†   r0   r1   r‹     rŒ   c                   s   g | ]}|ˆ vr|‘qS r0   r0   rŠ   r�   r0   r1   r‹     rŒ   )rˆ   )r�   rr   r6   r‚   rs   )rB   r†   r‡   rˆ   Z
merge_keysZmergedrV   Zmerged_itemr0   )r†   r‡   r1   r‚   ò   s$   


&€zValueItems.mergec                 C  sD   t | tƒr	 | S t | tƒrt | d¡} | S t| ddƒ}td|› �ƒ‚)N.r€   z???z!Unexpected type of exclude value )r5   r   r   rT   ÚfromkeysÚgetattrr@   )rS   Ú
class_namer0   r0   r1   rl     s   

ûþzValueItems._coerce_itemsc                 C  s    |d u s	|   |¡r|S |  |¡S r4   )rr   rl   )rB   rj   r0   r0   r1   r�   #  s   
zValueItems._coerce_valuer3   c                 C  s   | du p| du S )NT.r0   r:   r0   r0   r1   rr   )  ó   zValueItems.is_trueú_repr.ReprArgsc                 C  s   d | j fgS r4   rh   ©ro   r0   r0   r1   Ú__repr_args__-  ó   zValueItems.__repr_args__N)rj   r   rS   rk   r+   rY   )rq   r   r+   r,   )rw   rx   r+   ry   )rS   r$   r{   r|   r+   r}   )F)r†   r   r‡   r   rˆ   r,   r+   r   )rS   rk   r+   r$   )rj   r   r+   r   ©r3   r   r+   r,   )r+   r’   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__rp   ru   rv   rz   rm   Úclassmethodr‚   Ústaticmethodrl   r�   rr   r”   r0   r0   r0   r1   rg   «   s"    




%%
rg   ÚnameÚ	get_valueúCallable[[], T]c                 C  ó   d S r4   r0   ©rž   rŸ   r0   r0   r1   ÚLazyClassAttribute3  s    r£   c                   @  s2   e Zd ZdZddd	„Zeddd„ƒZddd„ZdS )r£   z­A descriptor exposing an attribute only accessible on a class (hidden from instances).

        The attribute is lazily computed and cached during the first access.
        rž   rI   rŸ   úCallable[[], Any]r+   rY   c                 C  s   || _ || _d S r4   r¢   )ro   rž   rŸ   r0   r0   r1   rp   =  s   
zLazyClassAttribute.__init__r   c                 C  s   |   ¡ S r4   )rŸ   r“   r0   r0   r1   rj   A  s   zLazyClassAttribute.valueÚinstanceÚownerú	type[Any]c                 C  s&   |d u r| j S t| j›d|j›d�ƒ‚)Nz attribute of z is class-only)rj   ÚAttributeErrorrž   r—   )ro   r¥   r¦   r0   r0   r1   Ú__get__E  s   zLazyClassAttribute.__get__N)rž   rI   rŸ   r¤   r+   rY   )r+   r   )r¥   r   r¦   r§   r+   r   )r—   r˜   r™   rš   rp   r   rj   r©   r0   r0   r0   r1   r£   7  s    
ÚObjÚobjc              
   C  s~   | t u s| tu r
| S | j}|tv r| S z| s&|tv r+|tu r!| W S |  ¡ W S W t
| ƒS W t
| ƒS  ttt	fy>   Y t
| ƒS w )z¬Return type as is for immutable built-in types
    Use obj.copy() for built-in empty collections
    Use copy.deepcopy() for non-empty collections and unknown objects.
    )r   r   r€   r(   r)   r7   rR   r@   Ú
ValueErrorÚRuntimeErrorr
   )r«   Úobj_typer0   r0   r1   Úsmart_deepcopyN  s    þùüür¯   ÚleftúIterable[Any]Úrightc                 C  s*   t | |td�D ]\}}||ur dS qdS )a  Check that the items of `left` are the same objects as those in `right`.

    >>> a, b = object(), object()
    >>> all_identical([a, b, a], [a, b, a])
    True
    >>> all_identical([a, b, [a]], [a, b, [a]])  # new list object, while "equal" is not "identical"
    False
    )Ú	fillvalueFT)r   Ú	_SENTINEL)r°   r²   Z	left_itemZ
right_itemr0   r0   r1   Úall_identicalf  s
   	ÿrµ   ÚaÚbc                 C  s   | dur| S |S )zTReturn the first argument if it is not `None`, otherwise return the second argument.Nr0   )r¶   r·   r0   r0   r1   Úget_first_not_noneu  r‘   r¸   T)ÚfrozenÚslotsc                   @  s6   e Zd ZU dZded< ddd	„Zerddd„ZdS dS )ÚSafeGetItemProxyz¦Wrapper redirecting `__getitem__` to `get` with a sentinel value as default

    This makes it safe to use in `operator.itemgetter` when some keys may be missing
    zMapping[str, Any]ÚwrappedÚkeyrI   r+   r   c                C  s   | j  |t¡S r4   )r¼   rs   r´   ©ro   r½   r0   r0   r1   Ú__getitem__ƒ  s   zSafeGetItemProxy.__getitem__r,   c                C  s   | j  |¡S r4   )r¼   Ú__contains__r¾   r0   r0   r1   rÀ   Œ  r•   zSafeGetItemProxy.__contains__N)r½   rI   r+   r   )r½   rI   r+   r,   )r—   r˜   r™   rš   Ú__annotations__r¿   r   rÀ   r0   r0   r0   r1   r»   z  s   
 
þr»   Ú_ModelTr'   )ÚboundÚ_RTc                   @  sL   e Zd ZdZddd„Zeddd„ƒZeeddd�ddd„ƒƒZddd„ZdS )Údeprecated_instance_propertya›  A decorator exposing the decorated class method as a property, with a warning on instance access.

    This decorator takes a class method defined on the `BaseModel` class and transforms it into
    an attribute. The attribute can be accessed on both the class and instances of the class. If accessed
    via an instance, a deprecation warning is emitted stating that instance access will be removed in V3.
    ÚfgetúCallable[[type[_ModelT]], _RT]r+   rY   c                C  s
   || _ d S r4   )rÆ   )ro   rÆ   r0   r0   r1   rp   œ  s   
z%deprecated_instance_property.__init__r¥   Úobjtypeútype[_ModelT]rÄ   c                 C  r¡   r4   r0   ©ro   r¥   rÈ   r0   r0   r1   r©      s   z$deprecated_instance_property.__get__z›Accessing this attribute on the instance is deprecated, and will be removed in Pydantic V3. Instead, you should access this attribute from the model class.N)ÚcategoryrÂ   c                 C  r¡   r4   r0   rÊ   r0   r0   r1   r©   ¢  s   ú_ModelT | Nonec                 C  s4   |d urt jd| jj›d�tdd� | j ||¡ƒ S )NzAccessing the zi attribute on the instance is deprecated. Instead, you should access this attribute from the model class.r&   )rË   Ú
stacklevel)ÚwarningsÚwarnrÆ   r—   r   r©   rÊ   r0   r0   r1   r©   ©  s   ü)rÆ   rÇ   r+   rY   )r¥   rY   rÈ   rÉ   r+   rÄ   )r¥   rÂ   rÈ   rÉ   r+   rÄ   )r¥   rÌ   rÈ   rÉ   r+   rÄ   )r—   r˜   r™   rš   rp   r   r©   r   r0   r0   r0   r1   rÅ   ”  s    
ýrÅ   )r*   r   r+   r,   r–   )r<   r   r=   r>   r+   r,   )rB   r   r=   r   r+   r,   )rB   r   r+   rF   )rH   rI   r+   r,   )rO   rP   rQ   rP   r+   rP   )rO   rW   rX   r   r+   rY   )r_   r`   r^   ra   r+   rb   )rž   rI   rŸ   r    r+   r]   )r«   rª   r+   rª   )r°   r±   r²   r±   r+   r,   )r¶   r   r·   r   r+   r   )frš   Ú
__future__r   Z_annotationsÚdataclassesrK   rÎ   ÚweakrefÚcollectionsr   r   r   Úcollections.abcr   r   r   r	   r   rR   r
   Ú	functoolsr   Úinspectr   Ú	itertoolsr   Útypesr   r   r   r   r   r   r   Útypingr   r   r   r   r   r   r   Zpydantic_corer   r   Ztyping_extensionsr   Zpydanticr   Ú r!   r"   Z_import_utilsr#   r|   rI   r$   rÁ   r%   Úmainr'   ÚfloatÚcomplexr,   ÚbytesrC   ÚrefÚNotImplementedr€   ÚEllipsisr(   r6   r8   r7   r9   rT   r)   r2   r;   rA   rE   rG   rM   rN   rU   r\   r]   rf   ZRepresentationrg   r£   rª   r¯   Úobjectr´   rµ   r¸   Ú	dataclassr»   rÂ   rÄ   rÅ   r0   r0   r0   r1   Ú<module>   sš    $$ íø




	
	

ý 


