
    q`o                     z   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 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j2                  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jF                  dfdZ$ddejJ                  dfdZ&y# e$ r	 ddl	mZ Y w xY w)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y)_UnboundCachec                      y N selfs    /lib/python3.12/site-packages/cachetools/func.pyr   z_UnboundCache.maxsize           c                     t        |       S r   )lenr   s    r   r   z_UnboundCache.currsize#   s    4yr   N)__name__
__module____qualname__propertyr   r   r   r   r   r   r      s(       r   r   c                   "    e Zd Zd Zed        Zy)_UnboundTTLCachec                 P    t        j                  | t        j                  ||       y r   )r   __init__mathinf)r   ttltimers      r   r)   z_UnboundTTLCache.__init__)   s    $#u5r   c                      y 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  r   r'   c                 2      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                  B    | 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 Y   nxY w | i |}	 5  j                  ||      cd d d        S # 1 sw Y   y xY w# 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!HMH	" "
   "!HMH"" " " d%f%A 2 ++Aq12 2 2 sV   A+AAAAA&B (B:	B B	B B BBc                      5  \  } }j                   }j                  }d d d        t               S # 1 sw Y   xY wr   )r   r   
_CacheInfo)r   r   r   r   r9   r<   r=   s       r   
cache_infoz-_cache.<locals>.decorator.<locals>.cache_infoJ   sI     *$f-- >>* dFGX>>	* *s	   8Ac                  ~    5  	  j                          ddgd d  	 d d d        y # ddgd d  w xY w# 1 sw Y   y xY w)Nr   )clear)r9   r<   r=   s   r   cache_clearz._cache.<locals>.decorator.<locals>.cache_clearQ   sL     &&KKM !1vE!H	& & !"1vE!H	& &s   3'3	03<c                       dS )Nr   typedr   rF   s   r   <lambda>z+_cache.<locals>.decorator.<locals>.<lambda>Z   s    w+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   sg    $dmm$,,wA	 	"	?	& ()#O   $/r   )r   )r9   rG   rN   r   s   `` @r   _cacherO   1   s    mmG(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.

    rP   )rO   r   callabler   rF   s     r   
fifo_cacherS   a   sJ     mou--	'	,vine,W55i(%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.

    rP   )rO   r   rR   r   rF   s     r   r   r   o   J     mou--	'	+vhsmU+G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.

    rP   )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.
    rP   )rO   r   rR   r	   rF   s     r   r   r      sJ    
 mou--	'	+vhsmU+G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.

    rP   )rO   r   rR   r
   )r   choicerG   s      r   r   r      sO     mou--	'	2vgc6*E27;;ggv.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.
    rP   )rO   r'   rR   r   )r   r,   r-   rG   s       r   r   r      sY    
 &sE2E::	'	7vhsC/7@@hwU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      s    E     &       
J $[##:

D x -`100
0 e 7 s$.. 
<w  &%&s   B, ,B:9B: