
    Ej.                       U d dl mZ d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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d          Z# ed          Z$ ed          Z% e!d          Z&de'd<    G d d          Z( e(            Z)de'd<    G d de          Z* G d de          Z+ G d dee#                   Z,e G d dee%e#f                               Z- G d d          Z.edGd$            Z/edHd'            Z/dId*Z/ed+d+d+d+d,dJd3            Z0edGd4            Z0edHd5            Z0	 dKd6d7d7dd,dLd9Z0edMd?            Z1edNdB            Z1e)fdOdFZ1dS )P    )annotations)AsyncCacheInfoAsyncCacheParametersAsyncLRUCacheWrappercache	lru_cachereduceN)OrderedDict)AsyncIterable	AwaitableCallable	CoroutineHashableIterable)update_wrapper)iscoroutinefunction)	AnyGeneric
NamedTuple	ParamSpec	TypedDictTypeVarcastfinaloverload)WeakKeyDictionary   )current_time)Lock)RunVar
checkpointTSPlru_cache_itemszRunVar[WeakKeyDictionary[AsyncLRUCacheWrapper[Any, Any], OrderedDict[Hashable, tuple[_InitialMissingType, Lock, float | None] | tuple[Any, None, float | None]]]]c                      e Zd ZdS )_InitialMissingTypeN)__name__
__module____qualname__     I/wd/license_services/venv/lib/python3.11/site-packages/anyio/functools.pyr'   r'   8   s        Dr,   r'   initial_missingc                  B    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   ?   s@         IIIKKKMMMOOOOOr,   r   c                  8    e Zd ZU ded<   ded<   ded<   ded<   dS )r   r3   r4   booltypedalways_checkpointr6   Nr7   r+   r,   r-   r   r   G   s:         KKKOOOOOr,   r   c                  6    e Zd ZddZddZdd
ZddZddZdS )_LRUMethodWrapperwrapperAsyncLRUCacheWrapper[..., T]instanceobjectc                "    || _         || _        d S N)_LRUMethodWrapper__wrapper_LRUMethodWrapper__instance)selfr?   rA   s      r-   __init__z_LRUMethodWrapper.__init__O   s     "r,   returnr   c                4    | j                                         S rD   )rE   
cache_inforG   s    r-   rK   z_LRUMethodWrapper.cache_infoS   s    ~((***r,   r   c                4    | j                                         S rD   )rE   cache_parametersrL   s    r-   rN   z"_LRUMethodWrapper.cache_parametersV   s    ~..000r,   Nonec                8    | j                                          d S rD   )rE   cache_clearrL   s    r-   rQ   z_LRUMethodWrapper.cache_clearY   s    ""$$$$$r,   argsr   kwargsr"   c                r   K   | j          | j        |i | d {V S  | j        | j         g|R i | d {V S rD   )rF   rE   )rG   rR   rS   s      r-   __call__z_LRUMethodWrapper.__call__\   sm      ?"'8888888888#T^DOEdEEEfEEEEEEEEEr,   N)r?   r@   rA   rB   rI   r   rI   r   rI   rO   )rR   r   rS   r   rI   r"   )r(   r)   r*   rH   rK   rN   rQ   rU   r+   r,   r-   r>   r>   N   s~        # # # #+ + + +1 1 1 1% % % %F F F F F Fr,   r>   c                  B    e Zd Zdd	ZddZd dZd!dZd"dZ	 d#d$dZdS )%r   funcCallable[P, Awaitable[T]]r4   r3   r;   r:   r<   r6   c                    || _         d| _        d| _        |t          |d          nd | _        d| _        || _        || _        || _        t          | |           d S Nr   )
__wrapped___hits_missesmax_maxsize	_currsize_typed_always_checkpoint_ttlr   )rG   rZ   r4   r;   r<   r6   s         r-   rH   zAsyncLRUCacheWrapper.__init__e   se      
+2+>GQD"3	tT"""""r,   rI   r   c                Z    t          | j        | j        | j        | j        | j                  S rD   )r   r_   r`   rb   rc   rf   rL   s    r-   rK   zAsyncLRUCacheWrapper.cache_infow   s)    JdmT^TY
 
 	
r,   r   c                8    | j         | j        | j        | j        dS )Nr4   r;   r<   r6   rb   rd   re   rf   rL   s    r-   rN   z%AsyncLRUCacheWrapper.cache_parameters|   s&    }[!%!89	
 
 	
r,   rO   c                    t                               d           x}r-|                    | d            dx| _        x| _        | _        d S d S r]   )r%   getpopr_   r`   rc   )rG   r   s     r-   rQ   z AsyncLRUCacheWrapper.cache_clear   sT    #''---5 	;IIdD!!!9::DJ:	; 	;r,   rR   P.argsrS   P.kwargsr"   c                d  K   | j         dk    r% | j        |i | d {V }| xj        dz  c_        |S |}|r.|t          ft	          |                                d          z   z  }| j        rU|t          d |D                       z  }|r7|t          ft          d |                                D                       z   z  }	 t          
                                }n8# t          $ r+ t                      }t                              |           Y nw xY w	 ||          }n## t          $ r t                      x}|| <   Y nw xY w	 ||         \  }}}	n7# t          $ r* t          t!          | j                   d }	}}|||	f||<   Y nw xY w||	Jt%                      |	k    r8| xj        dz  c_        t          t!          | j                   d }	}}|||	f||<   nU| xj        dz  c_        |                    |           | j        rt-                       d {V  t/          t0          |          S |4 d {V  ||         d         x}t          u r| xj        dz  c_        | j         '| j        | j         k    r|                    d           n| xj        dz  c_         | j        |i | d {V }| j        t%                      | j        z   nd }	|d |	f||<   n:| xj        dz  c_        |                    |           t/          t0          |          }	 d d d           d {V  n# 1 d {V swxY w Y   |S )	Nr   r   r+   c              3  4   K   | ]}t          |          V  d S rD   type).0args     r-   	<genexpr>z0AsyncLRUCacheWrapper.__call__.<locals>.<genexpr>   s(      33sc333333r,   c              3  4   K   | ]}t          |          V  d S rD   rr   )rt   vals     r-   rv   z0AsyncLRUCacheWrapper.__call__.<locals>.<genexpr>   s(      1W1W$s))1W1W1W1W1W1Wr,   )fast_acquireF)last)rb   r^   r`   r.   sumitemsrd   tuplevaluesr%   rl   LookupErrorr   setKeyErrorr
   r   re   r   rc   r_   move_to_endr!   r   r"   popitemrf   )
rG   rR   rS   valuekeyr   cache_entrycached_valuelock
expires_ats
             r-   rU   zAsyncLRUCacheWrapper.__call__   sp     =A*$*D;F;;;;;;;;ELLALLL  $ 	@O%FLLNNB(?(???C; 	X533d333333C X)E1W1Wv}}1W1W1W,W,WWW	'#''))EE 	' 	' 	'%''E&&&&&	'	6+KK 	6 	6 	6(35K%+++	6		>-8-=*L$

 	> 	> 	>  d&="=>>> !+$L
  ,T:=K	> <%,..J*F*F!##$*A&ABBB %/d
 $0z#AC   

a

'',,,* '$,,&&&&&&&A|,,, 	. 	. 	. 	. 	. 	. 	. 	. +C 0 33GG!=,4=1P1P''U'3333NNa'NN.d.?????????26)2GLNNTY..T  $)$
#:C   

a

'',,,Q---%	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.( sI   C 2DDD D>=D>E 1FF1CL
L),L)NrA   rB   ownertype | None_LRUMethodWrapper[T]c                P    t          | |          }t          || j                   |S rD   )r>   r   r^   )rG   rA   r   r?   s       r-   __get__zAsyncLRUCacheWrapper.__get__   s+     $D(33w 0111r,   )
rZ   r[   r4   r3   r;   r:   r<   r:   r6   r3   rV   rW   rX   )rR   rn   rS   ro   rI   r"   rD   )rA   rB   r   r   rI   r   )	r(   r)   r*   rH   rK   rN   rQ   rU   r   r+   r,   r-   r   r   c   s        # # # #$
 
 
 


 
 
 
; ; ; ;
O O O Od 6:      r,   r   c                  N    e Zd ZddZedd            Zedd            ZddZdS )_LRUCacheWrapperr4   r3   r;   r:   r<   r6   c                >    || _         || _        || _        || _        d S rD   rj   )rG   r4   r;   r<   r6   s        r-   rH   z_LRUCacheWrapper.__init__   s%      "3			r,   rZ   #Callable[P, Coroutine[Any, Any, T]]rI   AsyncLRUCacheWrapper[P, T]c                   d S rD   r+   rG   rZ   s     r-   rU   z_LRUCacheWrapper.__call__   s	     &)Sr,   Callable[..., T]functools._lru_cache_wrapper[T]c                   d S rD   r+   r   s     r-   rU   z_LRUCacheWrapper.__call__   s	     +.#r,   f6Callable[P, Coroutine[Any, Any, T]] | Callable[..., T]<AsyncLRUCacheWrapper[P, T] | functools._lru_cache_wrapper[T]c                   t          |          r't          || j        | j        | j        | j                  S  t          j        | j        | j                  |          S )N)r4   r;   )r   r   rb   rd   re   rf   	functoolsr   )rG   r   s     r-   rU   z_LRUCacheWrapper.__call__   sa     q!! 	'4=$+t/F	   My"4=LLLQOOOr,   N)r4   r3   r;   r:   r<   r:   r6   r3   rZ   r   rI   r   rZ   r   rI   r   )r   r   rI   r   )r(   r)   r*   rH   r   rU   r+   r,   r-   r   r      s            ) ) ) X) . . . X.P P P P P Pr,   r   rZ   r   rI   r   c                   d S rD   r+   rZ   s    r-   r   r      	     "%r,   r   r   c                   d S rD   r+   r   s    r-   r   r     s    ILr,   :Callable[..., Any] | Callable[P, Coroutine[Any, Any, Any]]r   c               4     t          d          |           S )z
    A convenient shortcut for :func:`lru_cache` with ``maxsize=None``.

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

    N)r4   )r   r   s    r-   r   r   
  s     #9T"""4(((r,   .ri   r4   r3   r;   r:   r<   r6   c                    d S rD   r+   ri   s       r-   r   r     s	     sr,   c                   d S rD   r+   r   s    r-   r   r     r   r,   c                   d S rD   r+   r   s    r-   r   r   $  s    MPSr,      FCCallable[..., Coroutine[Any, Any, Any]] | Callable[..., Any] | Nonec                  | t          ||||          S t          |           st          d           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   callable	TypeError)rZ   r4   r;   r<   r6   s        r-   r   r   (  s[    , |0A3GGGD>> ?=>>>CGU,=sCCDIIIr,   initialfunctionCallable[[T, S], Awaitable[T]]iterableIterable[S] | AsyncIterable[S]c               
   K   d S rD   r+   )r   r   r   s      r-   r	   r	   G  s       	r,   Callable[[T, T], Awaitable[T]]Iterable[T] | AsyncIterable[T]c               
   K   d S rD   r+   )r   r   s     r-   r	   r	   P  s      
 	r,   T | _InitialMissingType?Callable[[T, T], Awaitable[T]] | Callable[[T, S], Awaitable[T]]?Iterable[T] | Iterable[S] | AsyncIterable[T] | AsyncIterable[S]c                 K   d}t          |t                    r|                                }|t          u rM	 t	          t
          |                                 d{V           }n3# t          $ r t          d          dw xY wt	          t
          |          }|2 3 d{V } | ||           d{V }d}6 nt          |t                    rt          |          }|t          u rB	 t	          t
          t          |                    }n3# t          $ r t          d          dw xY wt	          t
          |          }|D ]} | ||           d{V }d}nt          d          |st                       d{V  |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_itr   elementits           r-   r	   r	   X  s     " O(M** U%%''o%%Qh&8&8&:&: : : : : : :;;%   F 
 G$$E% 	# 	# 	# 	# 	# 	# 	#'"(5'22222222E"OO &X 
Hh	'	' U(^^o%%QR))    F 
 G$$E 	# 	#G"(5'22222222E"OO	# STTT  llLs   -A& &BB7'"D
 
D%r   r   )rZ   r   rI   r   )
r4   r3   r;   r:   r<   r:   r6   r3   rI   r   rD   )rZ   r   r4   r3   r;   r:   r<   r:   r6   r3   rI   r   )r   r"   r   r   r   r   rI   r"   )r   r   r   r   rI   r"   )r   r   r   r   r   r   rI   r"   )2
__future__r   __all__r   collectionsr
   collections.abcr   r   r   r   r   r   r   inspectr   typingr   r   r   r   r   r   r   r   r   weakrefr   _core._eventloopr   _core._synchronizationr   lowlevelr    r!   r"   r#   r$   r%   r8   r'   r.   r   r   r>   r   r   r   r   r	   r+   r,   r-   <module>r      sm   " " " " " " "     # # # # # #                % $ $ $ $ $ ' ' ' ' ' '
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 & % % % % % * * * * * * ( ( ( ( ( ( ( ( ( ( ( ( ( (GCLLGCLLIcNN F  	 	 	 		 	 	 	 	 	 	 	 (;':'<'< < < < <    Z       9   F F F F F
 F F F* { { { { {71a4= { { {|P P P P P P P P< 
% % % 
%
 
 L L L 
 L) ) ) ) 
 !     
 
% % % 
%
 
 P P P 
 P QUJ #J J J J J J> 
   
 
   
 (7	8 8 8 8 8 8 8r,   