
    69j.                       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	 	 	 	 d.d        Z/ed/d!       Z/d0d"Z/ed#d#d#d#d$	 	 	 	 	 	 	 	 	 d1d%       Z0e	 	 	 	 d.d&       Z0ed/d'       Z0	 d2d(d)d)dd$	 	 	 	 	 	 	 	 	 	 	 d3d*Z0e	 	 	 	 	 	 	 	 d4d+       Z1e	 	 	 	 	 	 d5d,       Z1e)f	 	 	 	 	 	 	 d6d-Z1y)7    )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y)_InitialMissingTypeN)__name__
__module____qualname__     O/media/conek/DATA/Code/OCR/venv/lib/python3.12/site-packages/anyio/functools.pyr'   r'   8   s    r,   r'   initial_missingc                  @    e Zd ZU ded<   ded<   ded<   ded<   ded<   y)	r   inthitsmisses
int | NonemaxsizecurrsizettlNr(   r)   r*   __annotations__r+   r,   r-   r   r   ?   s    
IKM	Or,   r   c                  6    e Zd ZU ded<   ded<   ded<   ded<   y)r   r3   r4   booltypedalways_checkpointr6   Nr7   r+   r,   r-   r   r   G   s    K	Or,   r   c                  4    e Zd ZddZddZd	dZd
dZddZy)_LRUMethodWrapperc                     || _         || _        y N)_LRUMethodWrapper__wrapper_LRUMethodWrapper__instance)selfwrapperinstances      r-   __init__z_LRUMethodWrapper.__init__O   s     "r,   c                6    | j                   j                         S r@   )rA   
cache_inforC   s    r-   rH   z_LRUMethodWrapper.cache_infoS   s    ~~((**r,   c                6    | j                   j                         S r@   )rA   cache_parametersrI   s    r-   rK   z"_LRUMethodWrapper.cache_parametersV   s    ~~..00r,   c                8    | j                   j                          y r@   )rA   cache_clearrI   s    r-   rM   z_LRUMethodWrapper.cache_clearY   s    ""$r,   c                   K   | j                    | j                  |i | d {   S  | j                  | j                   g|i | d {   S 7 ,7 wr@   )rB   rA   )rC   argskwargss      r-   __call__z_LRUMethodWrapper.__call__\   sT     ??"'8888#T^^DOOEdEfEEE 9Es!   "AA'AAAAN)rD   zAsyncLRUCacheWrapper[..., T]rE   objectreturnr   rT   r   rT   None)rO   r   rP   r   rT   r"   )r(   r)   r*   rF   rH   rK   rM   rQ   r+   r,   r-   r>   r>   N   s    #+1%Fr,   r>   c                  ^    e Zd Z	 	 	 	 	 	 	 	 	 	 ddZd	dZd
dZddZddZ	 d	 	 	 	 	 ddZy)r   c                    || _         d| _        d| _        |t        |d      nd | _        d| _        || _        || _        || _        t        | |       y Nr   )
__wrapped___hits_missesmax_maxsize	_currsize_typed_always_checkpoint_ttlr   )rC   funcr4   r;   r<   r6   s         r-   rF   zAsyncLRUCacheWrapper.__init__e   sU      
+2+>GQD"3	tT"r,   c                    t        | j                  | j                  | j                  | j                  | j
                        S r@   )r   r\   r]   r_   r`   rc   rI   s    r-   rH   zAsyncLRUCacheWrapper.cache_infow   s.    JJdmmT^^TYY
 	
r,   c                `    | j                   | j                  | j                  | j                  dS )Nr4   r;   r<   r6   r_   ra   rb   rc   rI   s    r-   rK   z%AsyncLRUCacheWrapper.cache_parameters|   s*    }}[[!%!8!899	
 	
r,   c                    t         j                  d       x}r(|j                  | d        dx| _        x| _        | _        y y rZ   )r%   getpopr\   r]   r`   )rC   r   s     r-   rM   z AsyncLRUCacheWrapper.cache_clear   s@    #''--5-IIdD!9::DJ: .r,   c                r  K   | j                   dk(  r1 | j                  |i | d {   }| xj                  dz  c_        |S |}|r%|t        ft	        |j                         d      z   z  }| j                  rB|t        d |D              z  }|r+|t        ft        d |j                         D              z   z  }	 t        j                         }	 ||    }	 ||   \  }}}	||	Jt%               |	k\  r=| xj&                  dz  c_        t        t!        | j"                         d }	}}|||	f||<   nT| xj(                  dz  c_        |j+                  |       | j"                  rt-                d {    t/        t0        |      S |4 d {    ||   d   x}t        u r| xj                  dz  c_        | j                   ,| j&                  | j                   k\  r|j3                  d       n| xj&                  dz  c_         | j                  |i | d {   }| j4                  t%               | j4                  z   nd }	|d |	f||<   n6| xj(                  dz  c_        |j+                  |       t/        t0        |      }d d d       d {    |S 7 g# t        $ r# t               }t        j                  |       Y w xY w# t        $ r t               x}|| <   Y w xY w# t        $ r+ t        t!        | j"                         d }	}}|||	f||<   Y 3w xY w7 7 7 	7 # 1 d {  7  sw Y   S xY ww)	Nr   r   r+   c              3  2   K   | ]  }t        |        y wr@   type).0args     r-   	<genexpr>z0AsyncLRUCacheWrapper.__call__.<locals>.<genexpr>   s     3sc3   c              3  2   K   | ]  }t        |        y wr@   rn   )rp   vals     r-   rr   z0AsyncLRUCacheWrapper.__call__.<locals>.<genexpr>   s     1W$s)1Wrs   )fast_acquireF)last)r_   r[   r]   r.   sumitemsra   tuplevaluesr%   rj   LookupErrorr   setKeyErrorr
   r   rb   r   r`   r\   move_to_endr!   r   r"   popitemrc   )
rC   rO   rP   valuekeyr   cache_entrycached_valuelock
expires_ats
             r-   rQ   zAsyncLRUCacheWrapper.__call__   s&    ==A*$**D;F;;ELLALL  $O%FLLNB(???C;;53d333C)E1Wv}}1W,WWW	'#'')E
	6+K
		>-8-=*L$
 <%,.J*F!##$*A*A&AB %/d
 $0z#AC  

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

a
'',Q-%	. 	.( Y <"  	'%'E&	'  	6(35K%+	6  	>  d&=&="=> !+$L
  ,T:=K	>. '	. @	. 	. 	. 	.( s   %L7JBL7;J K  	K BL7,L-L7LL7BL!LA(L!<L7LL7(J=9L7<J==L7 KL7KL70LL7LL7L7L!L7!L4'L*(L4/L7Nc                J    t        | |      }t        || j                         |S r@   )r>   r   r[   )rC   rE   ownerrD   s       r-   __get__zAsyncLRUCacheWrapper.__get__   s%     $D(3w 0 01r,   )
rd   zCallable[P, Awaitable[T]]r4   r3   r;   r:   r<   r:   r6   r3   rS   rU   rV   )rO   zP.argsrP   zP.kwargsrT   r"   r@   )rE   rR   r   ztype | NonerT   z_LRUMethodWrapper[T])	r(   r)   r*   rF   rH   rK   rM   rQ   r   r+   r,   r-   r   r   c   so    #'# # 	#
  # #$


;
Od 6:'2	r,   r   c                  h    e Zd Z	 	 	 	 	 	 	 	 ddZe	 	 	 	 dd       Ze	 	 	 	 dd       Z	 	 	 	 d	dZy)
_LRUCacheWrapperc                <    || _         || _        || _        || _        y r@   rh   )rC   r4   r;   r<   r6   s        r-   rF   z_LRUCacheWrapper.__init__   s!      "3	r,   c                    y r@   r+   rC   rd   s     r-   rQ   z_LRUCacheWrapper.__call__   s     &)r,   c                    y r@   r+   r   s     r-   rQ   z_LRUCacheWrapper.__call__   s     +.r,   c                   t        |      r7t        || j                  | j                  | j                  | j
                        S  t        j                  | j                  | j                        |      S )N)r4   r;   )r   r   r_   ra   rb   rc   	functoolsr   )rC   fs     r-   rQ   z_LRUCacheWrapper.__call__   s[     q!'4==$++t/F/F		  My""4==LQOOr,   N)r4   r3   r;   r:   r<   r:   r6   r3   rd   z#Callable[P, Coroutine[Any, Any, T]]rT   zAsyncLRUCacheWrapper[P, T]rd   zCallable[..., T]rT   zfunctools._lru_cache_wrapper[T])r   z6Callable[P, Coroutine[Any, Any, T]] | Callable[..., T]rT   z<AsyncLRUCacheWrapper[P, T] | functools._lru_cache_wrapper[T])r(   r)   r*   rF   r   rQ   r+   r,   r-   r   r      s    !*.CGNX )7)	#) ) .$.	(. .PGP	EPr,   r   c                    y r@   r+   rd   s    r-   r   r           "%r,   c                    y r@   r+   r   s    r-   r   r     s    ILr,   c               &     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,   .rg   c                     y r@   r+   rg   s       r-   r   r     s     r,   c                    y r@   r+   r   s    r-   r   r     r   r,   c                    y r@   r+   r   s    r-   r   r   $  s    MPr,      Fc              v    | 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.

    z#the first argument must be callable)r   callable	TypeError)rd   r4   r;   r<   r6   s        r-   r   r   (  sH    , |0A3GGD>=>>CGU,=sCDIIr,   c                  K   y wr@   r+   )functioniterableinitials      r-   r	   r	   G  s      	   c                  K   y wr@   r+   )r   r   s     r-   r	   r	   P  s     
 	r   c                 K   d}t        |t              ro|j                         }|t        u r(	 t	        t
        |j                          d{         }nt	        t
        |      }|2 3 d{   } | ||       d{   }d}t        |t              rYt        |      }|t        u r	 t	        t
        t        |            }nt	        t
        |      }|D ]  } | ||       d{   }d} nt        d      |st                d{    |S 7 # t        $ r t        d      dw xY w7 7 6 7# t        $ r t        d      dw xY w7 d7 Bw)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  se    " O(M*%%'o%Qh&8&8&: :; G$E% 	# 	#'"5'22E"O	Hh	'(^o%QR) G$E 	#G"5'22E"O	# STT lLE !;% F	#2 & ! F 3 	s   +ED D
D E'D-+D),D-/E<D+=*E(D/ "E#E$#EE
ED D&&E)D-+E-E/EE
Er   r   )rd   z:Callable[..., Any] | Callable[P, Coroutine[Any, Any, Any]]rT   r   )
r4   r3   r;   r:   r<   r:   r6   r3   rT   r   r@   )rd   zCCallable[..., Coroutine[Any, Any, Any]] | Callable[..., Any] | Noner4   r3   r;   r:   r<   r:   r6   r3   rT   r   )r   r"   r   zCallable[[T, S], Awaitable[T]]r   zIterable[S] | AsyncIterable[S]rT   r"   )r   zCallable[[T, T], Awaitable[T]]r   zIterable[T] | AsyncIterable[T]rT   r"   )r   zT | _InitialMissingTyper   z?Callable[[T, T], Awaitable[T]] | Callable[[T, S], Awaitable[T]]r   z?Iterable[T] | Iterable[S] | AsyncIterable[T] | AsyncIterable[S]rT   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      s   "  #  % '
 
 
 & * ( (CLCLcN   	 		 	 (;'<$ <Z 9 F
 F* {71a4= { {|P P< 
%
-%% 
%
 
 L 
 L) 
 !  	
 
  
 
%
-%% 
%
 
 P 
 P QUJ #J
MJ 	J
 J J 
J 	J> 
 	,,
  
 
,, 	 
 (7	8 %	8M8M8
 8r,   