U
    #i1                     @  sb  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 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 dd	lmZmZ d
dlmZmZ d
dl m!Z! ej"rdZ#de$d< dZ%de$d< ddl&m'Z' e(e)e*e+e,e-e.ej/eeeej0eee1j2e3j2hZ4de$d< e5e6e7e8e9e	e
ehZ:de$d< dddddZ;ddddddZ<dddd d!d"Z=dd#d$d%d&Z>d'dd(d)d*Z?ed+Z@d,d,d,d-d.d/ZAd0dd1d2d3d4ZBed5ZCe+d6d7d8d9d:d;d<ZDG d=d> d>ejEZFej"rd'd5d5d?d@dAZGnG dBdA dAZGedCZHdCdCdDdEdFZIeJ ZKdGdGddHdIdJZLejMdKdLG dMdN dNZNdS )OzBucket 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)deepcopy)zip_longest)BuiltinFunctionTypeCodeTypeFunctionTypeGeneratorType
LambdaType
ModuleType)AnyMappingTypeVar)	TypeAlias	TypeGuard   )_repr_typing_extra)import_cached_base_modelz3typing.Mapping[int, Any] | typing.Mapping[str, Any]r   MappingIntStrAnyz1typing.AbstractSet[int] | typing.AbstractSet[str]AbstractSetIntStr   )	BaseModelzset[type[Any]]IMMUTABLE_NON_COLLECTIONS_TYPESBUILTIN_COLLECTIONSr   boolvreturnc                 C  s   t | ttttttfS N)
isinstancelisttupleset	frozensetr   r   r    r(   a/var/www/html/me.goteku.com/backend/venv/lib/python3.8/site-packages/pydantic/_internal/_utils.pysequence_likeA   s    r*   z(type[Any] | tuple[type[Any], ...] | None)oclass_or_tupler    c                 C  s(   zt | |W S  tk
r"   Y dS X d S NF)r"   	TypeError)r+   r,   r(   r(   r)   lenient_isinstanceE   s    r/   )clsr,   r    c                 C  sD   zt | tot| |W S  tk
r>   t | tjr8Y dS  Y nX d S r-   )r"   type
issubclassr.   r   ZWithArgsTypes)r0   r,   r(   r(   r)   lenient_issubclassL   s    r3   zTypeGuard[type[BaseModel]])r0   r    c                 C  s   t  }t| |o| |k	S )zReturns true if cls is a _proper_ subclass of BaseModel, and provides proper type-checking,
    unlike raw calls to lenient_issubclass.
    )r   r3   )r0   r   r(   r(   r)   is_model_classU   s    r4   str)
identifierr    c                 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)r6   r(   r(   r)   is_valid_identifier^   s    r:   KeyTypezdict[KeyType, Any])mappingupdating_mappingsr    c                 G  sd   |   }|D ]R}| D ]D\}}||krTt|| trTt|trTt|| |||< q|||< qq|S r!   )copyitemsr"   dictdeep_update)r<   r=   Zupdated_mappingZupdating_mappingkr   r(   r(   r)   rA   i   s     rA   zdict[Any, Any]None)r<   updater    c                 K  s   |  dd | D  d S )Nc                 S  s   i | ]\}}|d k	r||qS r!   r(   ).0rB   r   r(   r(   r)   
<dictcomp>u   s       z#update_not_none.<locals>.<dictcomp>)rD   r?   )r<   rD   r(   r(   r)   update_not_nonet   s    rG   T)name_factoryzlist[T] | tuple[T, ...]ztyping.Callable[[T], str]zlist[T])
input_listrI   r    c                C  sJ   g }g }| D ]8}||}||kr6| | | | 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)rJ   rI   resultZresult_namesr   Zv_namer(   r(   r)   unique_list{   s    	
rN   c                   @  s   e Zd ZdZdZddddddZdd	d
ddZdd	d
ddZdddddZddddddZ	e
d,ddd	ddddZeddddd Ze
ddd!d"d#Zedd	d$d%d&Zd'd(d)d*Zd+S )-
ValueItemszOClass for more convenient calculation of excluded or included fields on values.)_items_typer   z$AbstractSetIntStr | MappingIntStrAnyrC   )valuer?   r    c                 C  s2   |  |}t|ttfr(| |t|}|| _d S r!   )_coerce_itemsr"   r#   r$   _normalize_indexeslenrP   )selfrR   r?   r(   r(   r)   __init__   s    
zValueItems.__init__r   )itemr    c                 C  s   |  | j|S )zWCheck if item is fully excluded.

        :param item: key or index of a value
        )is_truerP   getrV   rX   r(   r(   r)   is_excluded   s    zValueItems.is_excludedc                 C  s
   || j kS )z`Check if value is contained in self._items.

        :param item: key or index of value
        rP   r[   r(   r(   r)   is_included   s    zValueItems.is_includedz	int | strz+AbstractSetIntStr | MappingIntStrAny | None)er    c                 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)rP   rZ   rY   )rV   r_   rX   r(   r(   r)   for_element   s    zValueItems.for_elementr   intzdict[int | str, Any])r?   v_lengthr    c           	      C  s
  i }d}|  D ]\}}t|tjsPt|tjsP| |sPtd| d|j |dkrd| |}qt|t	svtd|dk r|| n|}| 
|||||< q|s|S | |rt|D ]}||d q|S t|D ]*}||i }| |s| 
||||< q|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   .)r?   r"   typingr   AbstractSetrY   r.   	__class___coerce_valuera   mergerZ   range
setdefault)	rV   r?   rb   Znormalized_itemsZ	all_itemsir   Znormalized_inormalized_itemr(   r(   r)   rT      s2    	"



zValueItems._normalize_indexesF)baseoverride	intersectr    c                   s   |  |    dkr  S |  s2 dkr6S | rL|rH S S |rvfdd D  fddD  }nt  fddD  }i }|D ]0}| j |||d}|dk	r|||< q|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                   s   g | ]}| kr|qS r(   r(   rE   rB   )rn   r(   r)   
<listcomp>   s      z$ValueItems.merge.<locals>.<listcomp>c                   s   g | ]}| kr|qS r(   r(   rp   rm   r(   r)   rq      s      c                   s   g | ]}| kr|qS r(   r(   rp   rr   r(   r)   rq      s      )ro   )rg   rY   r#   rh   rZ   )r0   rm   rn   ro   Z
merge_keysZmergedrB   Zmerged_itemr(   )rm   rn   r)   rh      s"    


&
zValueItems.merge)r?   r    c                 C  sF   t | tjrn4t | tjr(t| d} nt| dd}td| | S )N.rf   z???z!Unexpected type of exclude value )r"   rd   r   re   r@   fromkeysgetattrr.   )r?   
class_namer(   r(   r)   rS      s    zValueItems._coerce_items)rR   r    c                 C  s    |d ks|  |r|S | |S r!   )rY   rS   )r0   rR   r(   r(   r)   rg   	  s    zValueItems._coerce_valuer   c                 C  s   | dkp| dkS )NT.r(   r'   r(   r(   r)   rY     s    zValueItems.is_truez_repr.ReprArgs)r    c                 C  s   d | j fgS r!   r]   )rV   r(   r(   r)   __repr_args__  s    zValueItems.__repr_args__N)F)__name__
__module____qualname____doc__	__slots__rW   r\   r^   r`   rT   classmethodrh   staticmethodrS   rg   rY   rv   r(   r(   r(   r)   rO      s    %%
rO   namerR   r    c                 C  s   d S r!   r(   r   rR   r(   r(   r)   ClassAttribute      r   c                   @  s8   e Zd ZdZdZddddddZdd	dd
ddZdS )r   z(Hide class attribute from its instances.r   r5   r   rC   r~   c                 C  s   || _ || _d S r!   r   )rV   r   rR   r(   r(   r)   rW   "  s    zClassAttribute.__init__z	type[Any])instanceownerr    c                 C  s*   |d kr| j S t| jd|jdd S )Nz attribute of z is class-only)rR   AttributeErrorr   rw   )rV   r   r   r(   r(   r)   __get__&  s    zClassAttribute.__get__N)rw   rx   ry   rz   r{   rW   r   r(   r(   r(   r)   r     s   Obj)objr    c              
   C  s\   | j }|tkr| S z&| s6|tkr6|tkr,| n|  W S W n tttfk
rR   Y nX t| S )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.
    )	rf   r   r   r$   r>   r.   
ValueErrorRuntimeErrorr   )r   obj_typer(   r(   r)   smart_deepcopy/  s    r   ztyping.Iterable[Any])leftrightr    c                 C  s*   t | |tdD ]\}}||k	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_itemr(   r(   r)   all_identicalE  s    	r   T)frozenc                   @  sD   e Zd ZU dZdZded< ddddd	Zejr@dd
dddZ	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   r5   r   )keyr    c                C  s   | j |tS r!   )r   rZ   r   rV   r   r(   r(   r)   __getitem__a  s    zSafeGetItemProxy.__getitem__r   c                C  s   | j |S r!   )r   __contains__r   r(   r(   r)   r   j  s    zSafeGetItemProxy.__contains__N)
rw   rx   ry   rz   r{   __annotations__r   rd   TYPE_CHECKINGr   r(   r(   r(   r)   r   T  s   
r   )Orz   
__future__r   Z_annotationsdataclassesr8   rd   weakrefcollectionsr   r   r   r>   r   	itertoolsr   typesr   r	   r
   r   r   r   r   r   r   typing_extensionsr   r    r   r   Z_import_utilsr   r   r   r   r   mainr   ra   floatcomplexr5   r   bytesr1   ZNoneTyperefNotImplementedrf   Ellipsisr   r#   r%   r$   r&   r@   r   r*   r/   r3   r4   r:   r;   rA   rG   rH   rN   ZRepresentationrO   r   r   r   objectr   r   	dataclassr   r(   r(   r(   r)   <module>   s    		 
