o
    +iM'                     @  s  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m Z  ej!dkrgd 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,eG dd dee&e$f Z-G dd dee$ Z.edJd#d$Z/edKd'd$Z/dLd*d$Z/ed+d+d+d,dMd3d4Z0edJd5d4Z0edKd6d4Z0	dNd7d8d8d,dOd;d4Z0edPdAdBZ1edQdEdBZ1e*fdRdIdBZ1dS )S    )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   )Lock)RunVar
checkpoint)      )	ParamSpecTSPlru_cache_itemszRunVar[WeakKeyDictionary[AsyncLRUCacheWrapper[Any, Any], OrderedDict[Hashable, tuple[_InitialMissingType, Lock] | tuple[Any, None]]]]c                   @  s   e Zd ZdS )_InitialMissingTypeN)__name__
__module____qualname__ r*   r*   B/var/www/html/venv/lib/python3.10/site-packages/anyio/functools.pyr&   8   s    r&   initial_missingc                   @  s.   e Zd ZU ded< ded< ded< ded< dS )r   inthitsmisses
int | NonemaxsizecurrsizeNr'   r(   r)   __annotations__r*   r*   r*   r+   r   ?   s
   
 r   c                   @  s&   e Zd ZU ded< ded< ded< dS )r   r0   r1   booltypedalways_checkpointNr3   r*   r*   r*   r+   r   F   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 )!r   funcCallable[..., Awaitable[T]]r1   r0   r6   r5   r7   c                 C  sJ   || _ d| _d| _|d urt|dnd | _d| _|| _|| _t| | d S Nr   )	__wrapped___hits_missesmax_maxsize	_currsize_typed_always_checkpointr   )selfr8   r1   r6   r7   r*   r*   r+   __init__N   s   zAsyncLRUCacheWrapper.__init__returnr   c                 C  s   t | j| j| j| jS N)r   r<   r=   r?   r@   rC   r*   r*   r+   
cache_info^   s   zAsyncLRUCacheWrapper.cache_infor   c                 C  s   | j | j| jdS )Nr1   r6   r7   r?   rA   rB   rG   r*   r*   r+   cache_parametersa   s   z%AsyncLRUCacheWrapper.cache_parametersNonec                 C  s4   t d  }r|| d  d | _ | _| _d S d S r:   )r%   getpopr<   r=   r@   )rC   r   r*   r*   r+   cache_clearh   s   z AsyncLRUCacheWrapper.cache_clearargsP.argskwargsP.kwargsr"   c           	   	     sL  | 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}}||f||< Y nw |d u r|  jd7  _|| | jrt I d H  tt|S |4 I d H Y || d  }tu r|  jd7  _| j d ur| j| j kr|jdd	 n|  jd7  _| j|i |I d H }|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 rF   type).0argr*   r*   r+   	<genexpr>{       z0AsyncLRUCacheWrapper.__call__.<locals>.<genexpr>c                 s  rT   rF   rU   )rW   valr*   r*   r+   rY   }   rZ   )fast_acquireF)last)r?   r;   r=   r,   sumitemsrA   tuplevaluesr%   rM   LookupErrorr   setKeyErrorr	   r   rB   r<   move_to_endr   r   r"   r@   popitem)	rC   rP   rR   valuekeyr   cache_entrycached_valuelockr*   r*   r+   __call__m   sh   
 


zAsyncLRUCacheWrapper.__call__N)r8   r9   r1   r0   r6   r5   r7   r5   )rE   r   )rE   r   )rE   rL   )rP   rQ   rR   rS   rE   r"   )r'   r(   r)   rD   rH   rK   rO   rl   r*   r*   r*   r+   r   L   s    



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 )_LRUCacheWrapperr1   r0   r6   r5   r7   c                 C  s   || _ || _|| _d S rF   rJ   )rC   r1   r6   r7   r*   r*   r+   rD      s   
z_LRUCacheWrapper.__init__r8   #Callable[P, Coroutine[Any, Any, T]]rE   AsyncLRUCacheWrapper[P, T]c                C     d S rF   r*   rC   r8   r*   r*   r+   rl         z_LRUCacheWrapper.__call__Callable[..., T]functools._lru_cache_wrapper[T]c                C  rp   rF   r*   rq   r*   r*   r+   rl      rr   f6Callable[P, Coroutine[Any, Any, T]] | Callable[..., T]<AsyncLRUCacheWrapper[P, T] | functools._lru_cache_wrapper[T]c                C  s2   t |rt|| j| j| jS tj| j| jd|S )N)r1   r6   )r   r   r?   rA   rB   	functoolsr   )rC   ru   r*   r*   r+   rl      s
   N)r1   r0   r6   r5   r7   r5   r8   rn   rE   ro   r8   rs   rE   rt   )ru   rv   rE   rw   )r'   r(   r)   rD   r   rl   r*   r*   r*   r+   rm      s    
rm   r8   rn   rE   ro   c                C  rp   rF   r*   r8   r*   r*   r+   r      rr   r   rs   rt   c                C  rp   rF   r*   r{   r*   r*   r+   r         6Callable[..., T] | Callable[P, Coroutine[Any, Any, T]]rw   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)r1   )r   r{   r*   r*   r+   r      s   	.rI   r1   r0   r6   r5   r7   _LRUCacheWrapper[Any]c                 C  rp   rF   r*   rI   r*   r*   r+   r      rr   r   c                C  rp   rF   r*   r{   r*   r*   r+   r      rr   c                C  rp   rF   r*   r{   r*   r*   r+   r      r|      F=Callable[P, Coroutine[Any, Any, T]] | Callable[..., T] | NoneTAsyncLRUCacheWrapper[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

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

    Nz#the first argument must be callable)rm   r   callable	TypeErrorr"   )r8   r1   r6   r7   r*   r*   r+   r      s
   initialfunctionCallable[[T, S], Awaitable[T]]iterableIterable[S] | AsyncIterable[S]c                     d S rF   r*   )r   r   r   r*   r*   r+   r     s   r   Callable[[T, T], Awaitable[T]]Iterable[T] | AsyncIterable[T]c                  r   rF   r*   )r   r   r*   r*   r+   r     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|st 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_itrg   elementitr*   r*   r+   r   #  sP   



ry   rz   )r8   r}   rE   rw   )r1   r0   r6   r5   r7   r5   rE   r~   rF   )
r8   r   r1   r0   r6   r5   r7   r5   rE   r   )r   r"   r   r   r   r   rE   r"   )r   r   r   r   rE   r"   )r   r   r   r   r   r   rE   r"   )2
__future__r   __all__rx   syscollectionsr	   collections.abcr
   r   r   r   r   r   r   inspectr   typingr   r   r   r   r   r   r   r   weakrefr   _core._synchronizationr   lowlevelr   r   version_infor!   typing_extensionsr"   r#   r$   r%   r4   r&   r,   r   r   r   rm   r   r   r   r*   r*   r*   r+   <module>   sf    	 (


e
