o
    niW>                     @  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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! ddl"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)m*Z* ddl+m,Z,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2m3Z3 ddl4m5Z5 e#re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@eAe3jBeee ejCee!eDjEeFjEhZGde9d< eHeIeJeKeLe
eehZMde9d< dgdd ZNdhd#d$ZOdid(d)ZPdjd+d,ZQdkd.d/ZRdld2d3ZSe&d4ZTdmd8d9ZUdnd=d>ZVe&d?ZWe7d@dodFdGZXG dHdI dIe2jYZZe#r)dpdMdNZ[nG dOdN dNZ[e&dPZ\dqdRdSZ]e^ Z_drdWdXZ`dsd[d\Zaejbd]d^G d_d` d`Zce&dadbdcZde&ddZeG dedf dfe%edeef ZfdS )tzBucket 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)TYPE_CHECKINGAnyGenericTypeVaroverload)MISSINGPydanticUndefined)	TypeAlias	TypeGuard
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)    r/   Y/var/www/html/arapca_proje/venv/lib/python3.10/site-packages/pydantic/_internal/_utils.pycan_be_positionalJ   s   r1   vr   c                 C  s   t | ttttttfS N)
isinstancelisttupleset	frozensetr   r   r2   r/   r/   r0   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)r4   	TypeError)r;   r<   r/   r/   r0   lenient_isinstancea   s
   r@   clsc                 C  s:   zt | to
t| |W S  ty   t | tjrY dS  w r>   )r4   type
issubclassr?   r!   WithArgsTypes)rA   r<   r/   r/   r0   lenient_issubclassh   s   rE   TypeGuard[type[BaseModel]]c                 C  s   t  }t| |o| |uS )zReturns true if cls is a _proper_ subclass of BaseModel, and provides proper type-checking,
    unlike raw calls to lenient_issubclass.
    )r"   rE   )rA   r&   r/   r/   r0   is_model_classq   s   rG   
identifierstrc                 C  s   |   o	t|  S )zChecks 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   r/   r/   r0   is_valid_identifierz   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 r3   )copyitemsr4   dictdeep_update)rO   rQ   updated_mappingupdating_mappingkr2   r/   r/   r0   rU      s    
rU   dict[Any, Any]updateNonec                 K  s   |  dd | D  d S )Nc                 S  s   i | ]\}}|d ur||qS r3   r/   ).0rX   r2   r/   r/   r0   
<dictcomp>   s    z#update_not_none.<locals>.<dictcomp>)rZ   rS   )rO   rZ   r/   r/   r0   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 )zMake 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)ra   r`   resultresult_namesr2   v_namer/   r/   r0   unique_list   s   	
rj   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_typevaluer   rS   $AbstractSetIntStr | MappingIntStrAnyr*   r[   c                 C  s2   |  |}t|ttfr| |t|}|| _d S r3   )_coerce_itemsr4   r5   r6   _normalize_indexeslenrl   )selfrn   rS   r/   r/   r0   __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_truerl   getrs   ru   r/   r/   r0   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
        rl   rx   r/   r/   r0   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)rl   rw   rv   )rs   r|   ru   r/   r/   r0   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__zExcluding fields from a sequence of sub-models or dicts must be performed index-wise: expected integer keys or keyword "__all__"r   .)rS   r4   r   AbstractSetrv   r?   	__class___coerce_valuer   mergerw   range
setdefault)	rs   rS   r   normalized_items	all_itemsir2   normalized_inormalized_itemr/   r/   r0   rq      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 r/   r/   r\   rX   )r   r/   r0   
<listcomp>      z$ValueItems.merge.<locals>.<listcomp>c                   r   r/   r/   r   r   r/   r0   r     r   c                   s   g | ]}| vr|qS r/   r/   r   r   r/   r0   r     r   )r   )r   rv   r5   r   rw   )rA   r   r   r   
merge_keysmergedrX   merged_itemr/   )r   r   r0   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 )r4   r   r   rT   fromkeysgetattrr?   )rS   
class_namer/   r/   r0   rp     s   

zValueItems._coerce_itemsc                 C  s    |d u s	|  |r|S | |S r3   )rv   rp   )rA   rn   r/   r/   r0   r   %  s   
zValueItems._coerce_valuer2   c                 C  s   | du p| du S )NT.r/   r9   r/   r/   r0   rv   +     zValueItems.is_true_repr.ReprArgsc                 C  s   d | j fgS r3   rz   rs   r/   r/   r0   __repr_args__/     zValueItems.__repr_args__N)rn   r   rS   ro   r*   r[   )ru   r   r*   r+   )r|   r}   r*   r~   )rS   r#   r   r   r*   r   )F)r   r   r   r   r   r+   r*   r   )rS   ro   r*   r#   )rn   r   r*   r   r2   r   r*   r+   )r*   r   )__name__
__module____qualname____doc__	__slots__rt   ry   r{   r   rq   classmethodr   staticmethodrp   r   rv   r   r/   r/   r/   r0   rk      s"    




%%
rk   name	get_valueCallable[[], T]c                 C     d S r3   r/   r   r   r/   r/   r0   LazyClassAttribute5  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   zA 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*   r[   c                 C  s   || _ || _d S r3   r   )rs   r   r   r/   r/   r0   rt   ?  s   
zLazyClassAttribute.__init__r   c                 C  s   |   S r3   )r   r   r/   r/   r0   rn   C  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)rn   AttributeErrorr   r   )rs   r   r   r/   r/   r0   __get__G  s   zLazyClassAttribute.__get__N)r   rI   r   r   r*   r[   )r*   r   )r   r   r   r   r*   r[   )r   r   r   r   rt   r   rn   r   r/   r/   r/   r0   r   9  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 )zReturn 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(   r6   rR   r?   
ValueErrorRuntimeErrorr
   )r   obj_typer/   r/   r0   smart_deepcopyP  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   	left_item
right_itemr/   r/   r0   all_identicalh  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.Nr/   )r   r   r/   r/   r0   get_first_not_nonew  r   r   T)frozenc                   @  s:   e Zd ZU dZdZded< dd	d
ZerdddZdS dS )SafeGetItemProxyzWrapper redirecting `__getitem__` to `get` with a sentinel value as default

    This makes is safe to use in `operator.itemgetter` when some keys may be missing
    )wrappedzMapping[str, Any]r   keyrI   r*   r   c                C  s   | j |tS r3   )r   rw   r   rs   r   r/   r/   r0   __getitem__  s   zSafeGetItemProxy.__getitem__r+   c                C  s   | j |S r3   )r   __contains__r   r/   r/   r0   r     r   zSafeGetItemProxy.__contains__N)r   rI   r*   r   )r   rI   r*   r+   )	r   r   r   r   r   __annotations__r   r   r   r/   r/   r/   r0   r   |  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*   r[   c                C  s
   || _ d S r3   )r   )rs   r   r/   r/   r0   rt     s   
z%deprecated_instance_property.__init__r   objtypetype[_ModelT]r   c                 C  r   r3   r/   rs   r   r   r/   r/   r0   r     s   z$deprecated_instance_property.__get__zAccessing 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   r3   r/   r   r/   r/   r0   r     s   _ModelT | Nonec                 C  sL   |d urt jdkr| jjn| jjj}tjd|dtdd | j|| S )N)   
   zAccessing the zi attribute on the instance is deprecated. Instead, you should access this attribute from the model class.r%   )r   
stacklevel)	sysversion_infor   r   __func__warningswarnr   r   )rs   r   r   	attr_namer/   r/   r0   r     s   

)r   r   r*   r[   )r   r[   r   r   r*   r   )r   r   r   r   r*   r   )r   r   r   r   r*   r   )r   r   r   r   rt   r   r   r   r/   r/   r/   r0   r     s    
r   )r)   r   r*   r+   r   )r;   r   r<   r=   r*   r+   )rA   r   r<   r   r*   r+   )rA   r   r*   rF   )rH   rI   r*   r+   )rO   rP   rQ   rP   r*   rP   )rO   rY   rZ   r   r*   r[   )ra   rb   r`   rc   r*   rd   )r   rI   r   r   r*   r_   )r   r   r*   r   )r   r   r   r   r*   r+   )r   r   r   r   r*   r   )gr   
__future__r   _annotationsdataclassesrK   r   r   weakrefcollectionsr   r   r   collections.abcr   r   r   r	   r   rR   r
   	functoolsr   inspectr   	itertoolsr   typesr   r   r   r   r   r   typingr   r   r   r   r   pydantic_corer   r   typing_extensionsr   r   r   pydanticr    r    r!   _import_utilsr"   r   rI   r#   r   r$   mainr&   floatcomplexr+   bytesrB   NoneTyperefNotImplementedr   Ellipsisr'   r5   r7   r6   r8   rT   r(   r1   r:   r@   rE   rG   rM   rN   rU   r^   r_   rj   Representationrk   r   r   r   objectr   r   r   	dataclassr   r   r   r   r/   r/   r/   r0   <module>   s      




	
	

 



