
    q`o                     r   d Z ddlZddlZddlZddlZddlZ	 ddlmZ n# e$ r	 ddl	mZ Y nw xY wddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ dZ ej        dg d          Z G d de          Z G d de          Zd ZddZddZ ddZ!ddZ"dej#        dfdZ$ddej%        dfdZ&dS )z?`functools.lru_cache` compatible memoizing function decorators.    N)RLock   )keys)	FIFOCache)LFUCache)LRUCache)MRUCache)RRCache)TTLCache)	lfu_cache	lru_cache	mru_cacherr_cache	ttl_cache	CacheInfo)hitsmissesmaxsizecurrsizec                   :    e Zd Zed             Zed             ZdS )_UnboundCachec                     d S N selfs    /lib/python3.11/site-packages/cachetools/func.pyr   z_UnboundCache.maxsize       t    c                      t          |           S r   )lenr   s    r   r   z_UnboundCache.currsize#   s    4yyr   N)__name__
__module____qualname__propertyr   r   r   r   r   r   r      sH          X   X  r   r   c                   *    e Zd Zd Zed             ZdS )_UnboundTTLCachec                 H    t          j        | t          j        ||           d S r   )r   __init__mathinf)r   ttltimers      r   r)   z_UnboundTTLCache.__init__)   s!    $#u55555r   c                     d S r   r   r   s    r   r   z_UnboundTTLCache.maxsize,   r   r   N)r"   r#   r$   r)   r%   r   r   r   r   r'   r'   (   s>        6 6 6   X  r   r'   c                 (      j          fd}|S )Nc                      	rt           j        nt           j        t                      ddg fd}fd}fd}||_        ||_        	fd|_        t          j        |            |S )Nr   c                  r    | i |}5  	 |         }dxx         dz  cc<   |cd d d            S # t           $ r dxx         dz  cc<   Y nw xY w	 d d d            n# 1 swxY w Y    | i |}	 5                      ||          cd d d            S # 1 swxY w Y   d S # t          $ r |cY S w xY w)Nr   r   )KeyError
setdefault
ValueError)	argskwargskvcachefunckeylockstatss	       r   wrapperz*_cache.<locals>.decorator.<locals>.wrapper9   s   T$V$$A " ""aA!HHHMHHH	" " " " " " " "
   " " "!HHHMHHHHH"" " " " " " " " " " " " " " " d%f%%A 2 2 ++Aq112 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2   sb   A!4AA!AA!!A%(A%5B' 7BB' BB' !B"B' 'B65B6c                      5  \  } }j         }j        }d d d            n# 1 swxY w Y   t          | |||          S r   )r   r   
_CacheInfo)r   r   r   r   r9   r<   r=   s       r   
cache_infoz-_cache.<locals>.decorator.<locals>.cache_infoJ   s     * *$f- >* * * * * * * * * * * * * * * dFGX>>>s   $((c                      5  	                                    ddgd d <   n# ddgd d <   w xY w	 d d d            d S # 1 swxY w Y   d S )Nr   )clear)r9   r<   r=   s   r   cache_clearz._cache.<locals>.decorator.<locals>.cache_clearQ   s     & &&KKMMM !1vE!!!HH1vE!!!H%%%%H	& & & & & & & & & & & & & & & & & &s#   A $
A /A  AAc                       dS )Nr   typedr   rF   s   r   <lambda>z+_cache.<locals>.decorator.<locals>.<lambda>Z   s    w+O+O r   )	r   typedkeyhashkeyr   rA   rD   cache_parameters	functoolsupdate_wrapper)
r:   r>   rA   rD   r;   r<   r=   r9   r   rG   s
   `   @@@r   	decoratorz_cache.<locals>.decorator4   s    $6dmm$,wwA	 	 	 	 	 	 	 	 	"	? 	? 	? 	? 	? 	? 	?	& 	& 	& 	& 	& 	& 	& ()#O#O#O#O#O  $///r   )r   )r9   rG   rN   r   s   `` @r   _cacherO   1   s8    mG( ( ( ( ( ( (T r      Fc                     | t          t                      |          S t          |           r& t          t          d          |          |           S t          t          |           |          S )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a First In First Out (FIFO)
    algorithm.

    NrP   )rO   r   callabler   rF   s     r   
fifo_cacherS   a   se     moou---	'		 1,vinne,,W555i((%000r   c                     | t          t                      |          S t          |           r& t          t          d          |          |           S t          t          |           |          S )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Least Frequently Used (LFU)
    algorithm.

    NrP   )rO   r   rR   r   rF   s     r   r   r   o   e     moou---	'		 0+vhsmmU++G444hw''///r   c                     | t          t                      |          S t          |           r& t          t          d          |          |           S t          t          |           |          S )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Least Recently Used (LRU)
    algorithm.

    NrP   )rO   r   rR   r   rF   s     r   r   r   }   rU   r   c                     | t          t                      |          S t          |           r& t          t          d          |          |           S t          t          |           |          S )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Most Recently Used (MRU)
    algorithm.
    NrP   )rO   r   rR   r	   rF   s     r   r   r      se    
 moou---	'		 0+vhsmmU++G444hw''///r   c                     | t          t                      |          S t          |           r' t          t          d|          |          |           S t          t          | |          |          S )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Random Replacement (RR)
    algorithm.

    NrP   )rO   r   rR   r
   )r   choicerG   s      r   r   r      sk     moou---	'		 72vgc6**E227;;;ggv..666r   iX  c                     | t          t          ||          |          S t          |           r( t          t          d||          |          |           S t          t          | ||          |          S )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Least Recently Used (LRU)
    algorithm with a per-item time-to-live (TTL) value.
    NrP   )rO   r'   rR   r   )r   r,   r-   rG   s       r   r   r      sv    
 &sE22E:::	'		 <7vhsC//77@@@hwU33U;;;r   )rP   F)'__doc__collectionsrL   r*   randomtime	threadingr   ImportErrordummy_threading r   fifor   lfur   lrur   mrur	   rrr
   r,   r   __all__
namedtupler@   dictr   r'   rO   rS   r   r   r   rY   r   	monotonicr   r   r   r   <module>rl      s0   E E           & & & &%%%%%%%%&                                          
J $[#::: 

    D       x   - - -`1 1 1 10 0 0 00 0 0 0
0 
0 
0 
0 e 7 7 7 7 s$. 
< 
< 
< 
< 
< 
<s    --