o
    Þ­j,/  ã                   @  s2  U d dl mZ dZd dlZd dl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 d dlmZ d dlmZmZmZmZmZ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!m"Z" ej#dkrmd dlm$Z$ nd dl%m$Z$ edƒZ&edƒZ'e$dƒZ(e!dƒZ)de*d< G dd„ dƒZ+e+ƒ Z,de*d< G dd„ deƒZ-G dd„ deƒZ.G dd„ dee& ƒZ/eG dd„ dee(e&f ƒƒZ0G d d!„ d!ee& ƒZ1edNd&d'„ƒZ2edOd*d'„ƒZ2dPd-d'„Z2ed.d.d.d.d/œdQd7d8„ƒZ3edNd9d8„ƒZ3edOd:d8„ƒZ3	dRd;d<d<dd/œdSd?d8„Z3edTdEdF„ƒZ4edUdIdF„ƒZ4e,fdVdMdF„Z4dS )Wé    )Úannotations)ÚAsyncCacheInfoÚAsyncCacheParametersÚAsyncLRUCacheWrapperÚcacheÚ	lru_cacheÚreduceN)ÚOrderedDict)ÚAsyncIterableÚ	AwaitableÚCallableÚ	CoroutineÚHashableÚIterable)Úupdate_wrapper)Úiscoroutinefunction)ÚAnyÚGenericÚ
NamedTupleÚ	TypedDictÚTypeVarÚcastÚfinalÚoverload)ÚWeakKeyDictionaryé   )Úcurrent_time)ÚLock)ÚRunVarÚ
checkpoint)é   é   )Ú	ParamSpecÚTÚSÚPÚlru_cache_itemsz¡RunVar[WeakKeyDictionary[AsyncLRUCacheWrapper[Any, Any], OrderedDict[Hashable, tuple[_InitialMissingType, Lock, float | None] | tuple[Any, None, float | None]]]]c                   @  s   e Zd ZdS )Ú_InitialMissingTypeN)Ú__name__Ú
__module__Ú__qualname__© r+   r+   úL/var/www/html/CropPilot/venv/lib/python3.10/site-packages/anyio/functools.pyr'   =   s    r'   Úinitial_missingc                   @  s6   e Zd ZU ded< ded< ded< ded< ded< dS )	r   ÚintÚhitsÚmissesú
int | NoneÚmaxsizeÚcurrsizeÚttlN©r(   r)   r*   Ú__annotations__r+   r+   r+   r,   r   D   s   
 r   c                   @  s.   e Zd ZU ded< ded< ded< ded< dS )r   r1   r2   ÚboolÚtypedÚalways_checkpointr4   Nr5   r+   r+   r+   r,   r   L   s
   
 r   c                   @  s>   e Zd Zddd„Zdd	d
„Zddd„Zddd„Zddd„ZdS )Ú_LRUMethodWrapperÚwrapperúAsyncLRUCacheWrapper[..., T]ÚinstanceÚobjectc                 C  s   || _ || _d S ©N)Ú_LRUMethodWrapper__wrapperÚ_LRUMethodWrapper__instance)Úselfr;   r=   r+   r+   r,   Ú__init__T   s   
z_LRUMethodWrapper.__init__Úreturnr   c                 C  ó
   | j  ¡ S r?   )r@   Ú
cache_info©rB   r+   r+   r,   rF   X   ó   
z_LRUMethodWrapper.cache_infor   c                 C  rE   r?   )r@   Úcache_parametersrG   r+   r+   r,   rI   [   rH   z"_LRUMethodWrapper.cache_parametersÚNonec                 C  s   | j  ¡  d S r?   )r@   Úcache_clearrG   r+   r+   r,   rK   ^   s   z_LRUMethodWrapper.cache_clearÚargsr   Úkwargsr#   c                 Ï  sB   �| j d u r| j|i |¤ŽI d H S | j| j g|¢R i |¤ŽI d H S r?   )rA   r@   )rB   rL   rM   r+   r+   r,   Ú__call__a   s   €
 z_LRUMethodWrapper.__call__N)r;   r<   r=   r>   ©rD   r   ©rD   r   ©rD   rJ   )rL   r   rM   r   rD   r#   )r(   r)   r*   rC   rF   rI   rK   rN   r+   r+   r+   r,   r:   S   s    



r:   c                   @  sL   e Zd Zd$d	d
„Zd%dd„Zd&dd„Zd'dd„Zd(dd„Z	d)d*d"d#„ZdS )+r   ÚfuncúCallable[P, Awaitable[T]]r2   r1   r8   r7   r9   r4   c                 C  sP   || _ d| _d| _|d urt|dƒnd | _d| _|| _|| _|| _t	| |ƒ d S ©Nr   )
Ú__wrapped__Ú_hitsÚ_missesÚmaxÚ_maxsizeÚ	_currsizeÚ_typedÚ_always_checkpointÚ_ttlr   )rB   rR   r2   r8   r9   r4   r+   r+   r,   rC   j   s   zAsyncLRUCacheWrapper.__init__rD   r   c                 C  s   t | j| j| j| j| jƒS r?   )r   rV   rW   rY   rZ   r]   rG   r+   r+   r,   rF   |   s   ÿzAsyncLRUCacheWrapper.cache_infor   c                 C  s   | j | j| j| jdœS )N©r2   r8   r9   r4   ©rY   r[   r\   r]   rG   r+   r+   r,   rI   �   s
   üz%AsyncLRUCacheWrapper.cache_parametersrJ   c                 C  s4   t  d ¡ }r| | d ¡ d | _ | _| _d S d S rT   )r&   ÚgetÚpoprV   rW   rZ   )rB   r   r+   r+   r,   rK   ‰   s   þz AsyncLRUCacheWrapper.cache_clearrL   úP.argsrM   úP.kwargsr#   c           
   	   Ï  sÄ  �| j dkr| j|i |¤ŽI d H }|  jd7  _|S |}|r*|tft| ¡ dƒ 7 }| jrJ|tdd„ |D ƒƒ7 }|rJ|tftdd„ | ¡ D ƒƒ 7 }zt	 
¡ }W n tya   tƒ }t	 |¡ Y nw z||  }W n tyx   tƒ  }|| < Y nw z	|| \}}}	W n tyŸ   tt| j d�d }}}	|||	f||< Y nw |d u rã|	d urÉtƒ |	krÉ|  jd8  _tt| j d�d }}}	|||	f||< n|  jd7  _| |¡ | jrÞtƒ I d H  tt|ƒS |4 I d H šk || d  }tu �r8|  jd7  _| j d u�r| j| j k�r|jdd	� n|  jd7  _| j|i |¤ŽI d H }| jd u�r.tƒ | j nd }	|d |	f||< n|  jd7  _| |¡ tt|ƒ}W d   ƒI d H  |S 1 I d H �s[w   Y  |S )
Nr   r   r+   c                 s  ó   � | ]}t |ƒV  qd S r?   ©Útype)Ú.0Úargr+   r+   r,   Ú	<genexpr>œ   ó   € z0AsyncLRUCacheWrapper.__call__.<locals>.<genexpr>c                 s  rd   r?   re   )rg   Úvalr+   r+   r,   ri   ž   rj   )Úfast_acquireF)Úlast)rY   rU   rW   r-   ÚsumÚitemsr[   ÚtupleÚvaluesr&   r`   ÚLookupErrorr   ÚsetÚKeyErrorr	   r   r\   r   rZ   rV   Úmove_to_endr   r   r#   Úpopitemr]   )
rB   rL   rM   ÚvalueÚkeyr   Úcache_entryÚcached_valueÚlockÚ
expires_atr+   r+   r,   rN   Ž   s|   €
 þÿ
ýù	
ý

ÿ
îìzAsyncLRUCacheWrapper.__call__Nr=   r>   Úownerútype | Noneú_LRUMethodWrapper[T]c                 C  s   t | |ƒ}t|| jƒ |S r?   )r:   r   rU   )rB   r=   r}   r;   r+   r+   r,   Ú__get__ß   s   
zAsyncLRUCacheWrapper.__get__)
rR   rS   r2   r1   r8   r7   r9   r7   r4   r1   rO   rP   rQ   )rL   rb   rM   rc   rD   r#   r?   )r=   r>   r}   r~   rD   r   )	r(   r)   r*   rC   rF   rI   rK   rN   r€   r+   r+   r+   r,   r   h   s    




Rÿr   c                   @  s<   e Zd Zddd„Zeddd„ƒZeddd„ƒZddd„ZdS )Ú_LRUCacheWrapperr2   r1   r8   r7   r9   r4   c                 C  s   || _ || _|| _|| _d S r?   r_   )rB   r2   r8   r9   r4   r+   r+   r,   rC   è   s   
z_LRUCacheWrapper.__init__rR   ú#Callable[P, Coroutine[Any, Any, T]]rD   úAsyncLRUCacheWrapper[P, T]c                C  ó   d S r?   r+   ©rB   rR   r+   r+   r,   rN   ð   ó   z_LRUCacheWrapper.__call__úCallable[..., T]úfunctools._lru_cache_wrapper[T]c                C  r„   r?   r+   r…   r+   r+   r,   rN   õ   r†   Úfú6Callable[P, Coroutine[Any, Any, T]] | Callable[..., T]ú<AsyncLRUCacheWrapper[P, T] | functools._lru_cache_wrapper[T]c                C  s6   t |ƒrt|| j| j| j| jƒS tj| j| jd�|ƒS )N)r2   r8   )r   r   rY   r[   r\   r]   Ú	functoolsr   )rB   r‰   r+   r+   r,   rN   ú   s
   ÿN)r2   r1   r8   r7   r9   r7   r4   r1   ©rR   r‚   rD   rƒ   ©rR   r‡   rD   rˆ   )r‰   rŠ   rD   r‹   )r(   r)   r*   rC   r   rN   r+   r+   r+   r,   r�   ç   s    
r�   rR   r‚   rD   rƒ   c                C  r„   r?   r+   ©rR   r+   r+   r,   r     r†   r   r‡   rˆ   c                C  r„   r?   r+   r�   r+   r+   r,   r     ó   ú6Callable[..., T] | Callable[P, Coroutine[Any, Any, T]]r‹   c                C  s   t dd�| ƒS )z’
    A convenient shortcut for :func:`lru_cache` with ``maxsize=None``.

    This is the asynchronous equivalent to :func:`functools.cache`.

    N)r2   )r   r�   r+   r+   r,   r     s   	.r^   r2   r1   r8   r7   r9   r4   ú_LRUCacheWrapper[Any]c                 C  r„   r?   r+   r^   r+   r+   r,   r     s   r   c                C  r„   r?   r+   r�   r+   r+   r,   r   %  r†   c                C  r„   r?   r+   r�   r+   r+   r,   r   +  r�   é€   Fú=Callable[P, Coroutine[Any, Any, T]] | Callable[..., T] | NoneúTAsyncLRUCacheWrapper[P, T] | functools._lru_cache_wrapper[T] | _LRUCacheWrapper[Any]c               C  s@   | du rt t ||||ƒS t| ƒstdƒ‚t t ||||ƒ| ƒS )aÞ  
    An asynchronous version of :func:`functools.lru_cache`.

    If a synchronous function is passed, the standard library
    :func:`functools.lru_cache` is applied instead.

    :param always_checkpoint: if ``True``, every call to the cached function will be
        guaranteed to yield control to the event loop at least once
    :param ttl: time in seconds after which to invalidate cache entries

    .. note:: Caches and locks are managed on a per-event loop basis.

    Nz#the first argument must be callable)r�   r   ÚcallableÚ	TypeErrorr#   )rR   r2   r8   r9   r4   r+   r+   r,   r   /  s
   ÚinitialÚfunctionúCallable[[T, S], Awaitable[T]]ÚiterableúIterable[S] | AsyncIterable[S]c                Ã  ó   �d S r?   r+   )r™   r›   r˜   r+   r+   r,   r   P  s   €r   úCallable[[T, T], Awaitable[T]]úIterable[T] | AsyncIterable[T]c                Ã  r�   r?   r+   )r™   r›   r+   r+   r,   r   Y  s   €úT | _InitialMissingTypeú?Callable[[T, T], Awaitable[T]] | Callable[[T, S], Awaitable[T]]ú?Iterable[T] | Iterable[S] | AsyncIterable[T] | AsyncIterable[S]c                Ã  s  �d}t |tƒrC| ¡ }|tu r)ztt| ¡ I dH ƒ}W n ty(   tdƒd‚w tt|ƒ}|2 z3 dH W }| ||ƒI dH }d}q06 n<t |t	ƒr{t
|ƒ}|tu rfz	ttt|ƒƒ}W n tye   tdƒd‚w tt|ƒ}|D ]}| ||ƒI dH }d}qmntdƒ‚|s‡tƒ I dH  |S )at  
    Asynchronous version of :func:`functools.reduce`.

    :param function: a coroutine function that takes two arguments: the accumulated
        value and the next element from the iterable
    :param iterable: an iterable or async iterable
    :param initial: the initial value (if missing, the first element of the iterable is
        used as the initial value)

    FNz0reduce() of empty sequence with no initial valueTz9reduce() argument 2 must be an iterable or async iterable)Ú
isinstancer
   Ú	__aiter__r-   r   r#   Ú	__anext__ÚStopAsyncIterationr—   r   ÚiterÚnextÚStopIterationr   )r™   r›   r˜   Úfunction_calledÚasync_itrw   ÚelementÚitr+   r+   r,   r   a  sP   €
ÿþÿ
þ
ÿþÿ
þr�   rŽ   )rR   r‘   rD   r‹   )
r2   r1   r8   r7   r9   r7   r4   r1   rD   r’   r?   )rR   r”   r2   r1   r8   r7   r9   r7   r4   r1   rD   r•   )r˜   r#   r™   rš   r›   rœ   rD   r#   )r™   rž   r›   rŸ   rD   r#   )r˜   r    r™   r¡   r›   r¢   rD   r#   )5Ú
__future__r   Ú__all__rŒ   ÚsysÚcollectionsr	   Úcollections.abcr
   r   r   r   r   r   r   Úinspectr   Útypingr   r   r   r   r   r   r   r   Úweakrefr   Ú_core._eventloopr   Ú_core._synchronizationr   Úlowlevelr   r   Úversion_infor"   Útyping_extensionsr#   r$   r%   r&   r6   r'   r-   r   r   r:   r   r�   r   r   r   r+   r+   r+   r,   Ú<module>   sr    	 (



÷~
û	ÿù!ü