
    `isU                        d Z d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Zddl	m
Z
  G d d          Z G d	 d
ej        j                  Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z ej        dg d          Ze
j        dddfdZe
j        dddfdZdS )z0Extensible memoizing collections and decorators.)	Cache	FIFOCacheLFUCacheLRUCacheRRCache	TLRUCacheTTLCachecachedcachedmethodz7.0.0    N   )keysc                   (    e Zd ZdZdZd Zd Zd ZdS )_DefaultSizezAA minimal "fake" dict that returns a constant size 1 for any key. c                     dS Nr   r   self_keys     g/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/cachetools/__init__.py__getitem__z_DefaultSize.__getitem__#       q    c                     d S Nr   )r   r   _values      r   __setitem__z_DefaultSize.__setitem__&   s    r   c                     dS r   r   r   s     r   popz_DefaultSize.pop)   r   r   N)__name__
__module____qualname____doc__	__slots__r   r   r   r   r   r   r   r      sL        KKI        r   r   c                       e Zd ZdZ e            Z e            ZddZd Z	d Z
d Zd Zd Zd	 Zd
 Zd ZddZefdZddZed             Zed             Zed             ZdS )r   z?Mutable mapping to serve as a simple cache or cache base class.Nc                     |r|| _         | j         t          j         urt                      | _        t                      | _        d| _        || _        d S Nr   )	getsizeofr   dict_Cache__size_Cache__data_Cache__currsize_Cache__maxsizer   maxsizer(   s      r   __init__zCache.__init__4   sH     	'&DN>00&&DKff r   c                 z    t          |           j        dt          | j                  d| j        d| j        dS )N(z
, maxsize=z, currsize=))typer    reprr+   r-   r,   r   s    r   __repr__zCache.__repr__=   sC    JJNNNOOO	
 	
r   c                 h    	 | j         |         S # t          $ r |                     |          cY S w xY wr   )r+   KeyError__missing__r   keys     r   r   zCache.__getitem__E   sI    	);s## 	) 	) 	)##C(((((	)s    11c                 |   | j         }|                     |          }||k    rt          d          || j        vs| j        |         |k     r0| j        |z   |k    r"|                                  | j        |z   |k    "|| j        v r|| j        |         z
  }n|}|| j        |<   || j        |<   | xj        |z  c_        d S )Nzvalue too large)r-   r(   
ValueErrorr+   r*   r,   popitem)r   r<   valuer/   sizediffsizes         r   r   zCache.__setitem__K   s    .~~e$$'>>.///dk!!T[%5%<%</D(722 /D(722$+dk#..HHH CC8#r   c                 j    | j                             |          }| j        |= | xj        |z  c_        d S r   )r*   r   r+   r,   )r   r<   rA   s      r   __delitem__zCache.__delitem__[   s3    {s##K4r   c                     || j         v S r   )r+   r;   s     r   __contains__zCache.__contains__`   s    dk!!r   c                      t          |          r   )r9   r;   s     r   r:   zCache.__missing__c   s    smmr   c                 *    t          | j                  S r   )iterr+   r6   s    r   __iter__zCache.__iter__f   s    DK   r   c                 *    t          | j                  S r   )lenr+   r6   s    r   __len__zCache.__len__i   s    4;r   c                     || v r| |         S |S r   r   )r   r<   defaults      r   getz	Cache.getr   s    $;;9Nr   c                 Z    || v r| |         }| |= n|| j         u rt          |          |}|S r   )_Cache__markerr9   r   r<   rO   r@   s       r   r   z	Cache.popx   s@    $;;IES		%%3--Er   c                 .    || v r	| |         }n|x| |<   }|S r   r   rS   s       r   
setdefaultzCache.setdefault   s)    $;;IEE ''DIr   c                     | j         S )zThe maximum size of the cache.)r-   r6   s    r   r/   zCache.maxsize   s     ~r   c                     | j         S )zThe current size of the cache.)r,   r6   s    r   currsizezCache.currsize   s     r   c                     dS )z+Return the size of a cache element's value.r   r   )r@   s    r   r(   zCache.getsizeof   s	     qr   r   )r    r!   r"   r#   objectrR   r   r*   r0   r7   r   r   rD   rF   r:   rJ   rM   rP   r   rU   propertyr/   rX   staticmethodr(   r   r   r   r   r   -   sN       IIvxxH\^^F! ! ! !
 
 
) ) )$ $ $      
" " "  ! ! !          (          X   X   \  r   r   c                   H    e Zd ZdZddZej        fdZej        fdZd ZdS )r   z/First In First Out (FIFO) cache implementation.Nc                 n    t                               | ||           t          j                    | _        d S r   )r   r0   collectionsOrderedDict_FIFOCache__orderr.   s      r   r0   zFIFOCache.__init__   ,    tWi000".00r   c                 ~     || ||           || j         v r| j                             |           d S d | j         |<   d S r   )ra   move_to_endr   r<   r@   cache_setitems       r   r   zFIFOCache.__setitem__   sQ    dC'''$,L$$S))))) $DLr   c                 .     || |           | j         |= d S r   )ra   r   r<   cache_delitems      r   rD   zFIFOCache.__delitem__   $    dC   Lr   c                     	 t          t          | j                            }||                     |          fS # t          $ r& t          dt          |           j        z            dw xY w)z9Remove and return the `(key, value)` pair first inserted.%s is emptyN)nextrI   ra   r   StopIterationr9   r4   r    r;   s     r   r?   zFIFOCache.popitem   t    	(tDL))**C #''  	J 	J 	J=4::+>>??TI	J	   !: 0A*r   )	r    r!   r"   r#   r0   r   r   rD   r?   r   r   r   r   r      su        991 1 1 1 5:4E % % % % .3->    ( ( ( ( (r   r   c                   |    e Zd ZdZ G d d          ZddZej        fdZej        fdZej	        fdZ	d	 Z
d
 ZdS )r   z1Least Frequently Used (LFU) cache implementation.c                       e Zd ZdZd Zd ZdS )LFUCache._Link)countr   rm   prevc                 :    || _         t                      | _        d S r   )rt   setr   )r   rt   s     r   r0   zLFUCache._Link.__init__   s    DJDIIIr   c                 >    | j         }| j        }||_         ||_        d S r   rm   ru   r   rm   ru   s      r   unlinkzLFUCache._Link.unlink   "    9D9DDIDIIIr   N)r    r!   r"   r$   r0   r{   r   r   r   _Linkrs      s7        5		 	 		 	 	 	 	r   r}   Nc                     t                               | ||           t                              d          x| _        }|x|_        |_        i | _        d S r'   )r   r0   r   r}   _LFUCache__rootru   rm   _LFUCache__links)r   r/   r(   roots       r   r0   zLFUCache.__init__   sI    tWi000%^^A...d $$	DIr   c                 P     || |          }|| v r|                      |           |S r   )_LFUCache__touchr   r<   cache_getitemr@   s       r   r   zLFUCache.__getitem__   3    dC(($;;LLr   c                 Z    || ||           || j         v r|                     |           d S | j        }|j        }|j        dk    r@t
                              d          }|j        |_        |x|_        |j        _        ||_        |j        	                    |           || j         |<   d S r   )
r   r   r   rm   rt   r   r}   ru   r   add)r   r<   r@   rf   r   links         r   r   zLFUCache.__setitem__   s    dC'''$,LLF{y:??>>!$$D	DI)--DI	DI	c Sr   c                      || |           | j                             |          }|j                            |           |j        s|                                 d S d S r   )r   r   r   remover{   r   r<   ri   r   s       r   rD   zLFUCache.__delitem__   sd    dC   |$$	y 	KKMMMMM	 	r   c                     | j         }|j        }||u r%t          dt          |           j        z            dt          t          |j                            }||                     |          fS )z@Remove and return the `(key, value)` pair least frequently used.rl   N)r   rm   r9   r4   r    rI   r   r   )r   r   currr<   s       r   r?   zLFUCache.popitem   sa    {y4<<=4::+>>??TI4	??##TXXc]]##r   c                    | j         |         }|j        }|j        |j        dz   k    rrt          |j                  dk    r|xj        dz  c_        dS t
                              |j        dz             }|j        |_        |x|_        |j        _        ||_        |j                            |           |j        	                    |           |j        s|
                                 || j         |<   dS )zIncrement use countr   N)r   rm   rt   rL   r   r   r}   ru   r   r   r{   )r   r<   r   r   s       r   __touchzLFUCache.__touch   s    |C y:a''49~~""

a

>>$*q.11D	DI)--DI	DI	c	y 	KKMMM Sr   r   )r    r!   r"   r#   r}   r0   r   r   r   rD   r?   r   r   r   r   r   r      s        ;;           .3->     5:4E ! ! ! ! .3->    $ $ $! ! ! ! !r   r   c                   b    e Zd ZdZd	dZej        fdZej        fdZej        fdZd Z	d Z
dS )
r   z/Least Recently Used (LRU) cache implementation.Nc                 n    t                               | ||           t          j                    | _        d S r   )r   r0   r_   r`   _LRUCache__orderr.   s      r   r0   zLRUCache.__init__  rb   r   c                 P     || |          }|| v r|                      |           |S r   _LRUCache__touchr   s       r   r   zLRUCache.__getitem__
  r   r   c                 J     || ||           |                      |           d S r   r   re   s       r   r   zLRUCache.__setitem__  s.    dC'''Sr   c                 .     || |           | j         |= d S r   )r   rh   s      r   rD   zLRUCache.__delitem__  rj   r   c                     	 t          t          | j                            }||                     |          fS # t          $ r& t          dt          |           j        z            dw xY w)z>Remove and return the `(key, value)` pair least recently used.rl   N)rm   rI   r   r   rn   r9   r4   r    r;   s     r   r?   zLRUCache.popitem  ro   rp   c                 r    	 | j                             |           dS # t          $ r d| j         |<   Y dS w xY w)zMark as recently usedN)r   rd   r9   r;   s     r   r   zLRUCache.__touch!  sS    	%L$$S))))) 	% 	% 	% $DL	%s    66r   )r    r!   r"   r#   r0   r   r   r   rD   r?   r   r   r   r   r   r     s        991 1 1 1 .3->     5:4E     .3->    ( ( (% % % % %r   r   c                   l    e Zd ZdZej        dfdZed             Zej	        fdZ	ej
        fdZ
d ZdS )r   z-Random Replacement (RR) cache implementation.Nc                 h    t                               | ||           || _        i | _        g | _        d S r   )r   r0   _RRCache__choice_RRCache__index_RRCache__keys)r   r/   choicer(   s       r   r0   zRRCache.__init__,  s1    tWi000r   c                     | j         S )z(The `choice` function used by the cache.)r   r6   s    r   r   zRRCache.choice2  s     }r   c                      || ||           || j         vr8t          | j                  | j         |<   | j                            |           d S d S r   )r   rL   r   appendre   s       r   r   zRRCache.__setitem__7  s]    dC'''dl"" #DK 0 0DLKs##### #"r   c                      || |           | j                             |          }|t          | j                  dz
  k    r!| j        d         }|| j        |<   || j         |<   | j                                         d S )Nr   )r   r   rL   r   )r   r<   ri   indexlasts        r   rD   zRRCache.__delitem__=  s~    dC     %%C$$q(((;r?D!%DK!&DLr   c                     	 |                      | j                  }||                     |          fS # t          $ r& t	          dt          |           j        z            dw xY w)z/Remove and return a random `(key, value)` pair.rl   N)r   r   r   
IndexErrorr9   r4   r    r;   s     r   r?   zRRCache.popitemF  sp    	(--,,C #''  	J 	J 	J=4::+>>??TI	Js	   3 0A#)r    r!   r"   r#   randomr   r0   r[   r   r   rD   r?   r   r   r   r   r   )  s        77'-}       X 5:4E $ $ $ $ .3->    ( ( ( ( (r   r   c                        e Zd ZdZ G d d          Zej        dfdZej	        fdZ	ej
        fdZ
e fd            Zed	             Zd
 Zd Zd Zd Z xZS )_TimedCachez0Base class for time aware cache implementations.c                   2    e Zd Zd Zd Zd Zd Zd Zd ZdS )_TimedCache._Timerc                 "    || _         d| _        d S r'   )_Timer__timer_Timer__nesting)r   timers     r   r0   z_TimedCache._Timer.__init__T  s     DLDNNNr   c                 N    | j         dk    r|                                 S | j        S r'   r   r   _Timer__timer6   s    r   __call__z_TimedCache._Timer.__call__X  s%    ~""||~~%{"r   c                     | j         dk    r|                                 x| _        }n| j        }| xj         dz  c_         |S )Nr   r   r   r   times     r   	__enter__z_TimedCache._Timer.__enter__^  sA    ~""%)\\^^3dd{NNaNNKr   c                 &    | xj         dz  c_         d S r   )r   )r   excs     r   __exit__z_TimedCache._Timer.__exit__f  s    NNaNNNNr   c                 *    t           j        | j        ffS r   )r   _Timerr   r6   s    r   
__reduce__z_TimedCache._Timer.__reduce__i  s    %66r   c                 ,    t          | j        |          S r   )getattrr   )r   names     r   __getattr__z_TimedCache._Timer.__getattr__l  s    4<...r   N)	r    r!   r"   r0   r   r   r   r   r   r   r   r   r   r   S  sn        	 	 		# 	# 	#	 	 		  	  	 	7 	7 	7	/ 	/ 	/ 	/ 	/r   r   Nc                 |    t                               | ||           t                              |          | _        d S r   )r   r0   r   r   _TimedCache__timer)r   r/   r   r(   s       r   r0   z_TimedCache.__init__o  s1    tWi000"))%00r   c                     | j         5 }|                     |            ||           cd d d            S # 1 swxY w Y   d S r   r   expire)r   
cache_reprr   s      r   r7   z_TimedCache.__repr__s  s    \ 	$TKK:d##	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$    599c                     | j         5 }|                     |            ||           cd d d            S # 1 swxY w Y   d S r   r   )r   	cache_lenr   s      r   rM   z_TimedCache.__len__x  s    \ 	#TKK9T??	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	# 	#r   c                     | j         5 }|                     |           t                      j        cd d d            S # 1 swxY w Y   d S r   )r   r   superrX   )r   r   	__class__s     r   rX   z_TimedCache.currsize}  s    \ 	$TKK77#	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$ 	$s   (>AAc                     | j         S )z%The timer function used by the cache.)r   r6   s    r   r   z_TimedCache.timer  s     |r   c                     | j         5 }|                     |           t                              |            d d d            d S # 1 swxY w Y   d S r   )r   r   r   clearr   s     r   r   z_TimedCache.clear  s    \ 	TKKKK	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   0AA	A	c                 n    | j         5  t          j        | g|R i |cd d d            S # 1 swxY w Y   d S r   )r   r   rP   r   argskwargss      r   rP   z_TimedCache.get      \ 	4 	49T3D333F33	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4   *..c                 n    | j         5  t          j        | g|R i |cd d d            S # 1 swxY w Y   d S r   )r   r   r   r   s      r   r   z_TimedCache.pop  r   r   c                 n    | j         5  t          j        | g|R i |cd d d            S # 1 swxY w Y   d S r   )r   r   rU   r   s      r   rU   z_TimedCache.setdefault  s    \ 	; 	;#D:4:::6::	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;r   )r    r!   r"   r#   r   r   	monotonicr0   r   r7   rM   r[   rX   r   r   rP   r   rU   __classcell__)r   s   @r   r   r   P  s       ::/ / / / / / / /8 '+n 1 1 1 1 #(. $ $ $ $
 !& # # # #
 $ $ $ $ X$
   X  
4 4 44 4 4; ; ; ; ; ; ;r   r   c                       e Zd ZdZ G d d          Zej        dfdZd Ze	j
        fdZ
e	j        fdZe	j        fd	Zd
 Zd Zed             ZddZd Zd ZdS )r   z@LRU Cache implementation with per-item time-to-live (TTL) value.c                   &    e Zd ZdZddZd Zd ZdS )TTLCache._Link)r<   expiresrm   ru   Nc                 "    || _         || _        d S r   )r<   r   r   r<   r   s      r   r0   zTTLCache._Link.__init__  s    DH"DLLLr   c                 6    t           j        | j        | j        ffS r   )r   r}   r<   r   r6   s    r   r   zTTLCache._Link.__reduce__  s    >DHdl#;;;r   c                 >    | j         }| j        }||_         ||_        d S r   ry   rz   s      r   r{   zTTLCache._Link.unlink  r|   r   NN)r    r!   r"   r$   r0   r   r{   r   r   r   r}   r     sK        6		# 	# 	# 	#	< 	< 	<	 	 	 	 	r   r}   Nc                     t                               | |||           t                                          x| _        }|x|_        |_        t          j                    | _	        || _
        d S r   )r   r0   r   r}   _TTLCache__rootru   rm   r_   r`   _TTLCache__links_TTLCache__ttl)r   r/   ttlr   r(   r   s         r   r0   zTTLCache.__init__  s[    T7E9===%^^---d $$	DI".00


r   c                 z    	 | j         |         }|                                 |j        k     S # t          $ r Y dS w xY wNF)r   r   r   r9   )r   r<   r   s      r   rF   zTTLCache.__contains__  N    	/<$D ::<<$,..  	 	 	55	   , 
::c                     	 |                      |          }|                                 |j        k      }n# t          $ r d}Y nw xY w|r|                     |          S  || |          S r   )_TTLCache__getlinkr   r   r9   r:   )r   r<   r   r   expireds        r   r   zTTLCache.__getitem__      	8>>#&&D  ::<<$,67GG  	 	 	GGG	  	,##C((( =s+++   6 AAc                    | j         5 }|                     |            || ||           d d d            n# 1 swxY w Y   	 |                     |          }|                                 n4# t          $ r' t
                              |          x| j        |<   }Y nw xY w|| j        z   |_	        | j
        x|_        }|j        x|_        }|x|_        |_        d S r   )r   r   r   r{   r9   r   r}   r   r   r   r   rm   ru   )r   r<   r@   rf   r   r   r   ru   s           r   r   zTTLCache.__setitem__  s%   Z 	,4KKM$U+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,	>>#&&D KKMMMM  	; 	; 	;'/~~c':'::DL	; dj(;&	D9$	D $$	DIIIs   #7;;A- -.BBc                      || |           | j                             |          }|                                 |                                 |j        k     st          |          d S r   )r   r   r{   r   r   r9   r   s       r   rD   zTTLCache.__delitem__  s_    dC   |$$

t|++3-- ,+r   c              #      K   | j         }|j        }||ur@| j        5 }||j        k     r	|j        V  d d d            n# 1 swxY w Y   |j        }||u>d S d S r   )r   rm   r   r   r<   )r   r   r   r   s       r   rJ   zTTLCache.__iter__  s      {y$ #t$,&&(NNN# # # # # # # # # # # # # # # 9D $s   =AAc                 P   | j                             |           | j        }|x|_        |_        t          | j                                        d           D ]%}||_        |j        x|_        }|x|_        |_        &|                     | 	                                           d S )Nc                     | j         S r   r   )objs    r   <lambda>z'TTLCache.__setstate__.<locals>.<lambda>  s    #+ r   )r<   )
__dict__updater   ru   rm   sortedr   valuesr   r   )r   stater   r   ru   s        r   __setstate__zTTLCache.__setstate__  s    U###{ $$	DI4<..006M6MNNN 	) 	)DDI#y(DI$((DI		DJJLL!!!!!r   c                     | j         S )z,The time-to-live value of the cache's items.)r   r6   s    r   r   zTTLCache.ttl       zr   c                    ||                                  }| j        }|j        }| j        }g }t          j        }t          j        }||ur{||j        k     sp|                    |j	         || |j	                  f            || |j	                   ||j	        = |j        }|
                                 |}||ur||j        k     p|S )qRemove expired items from the cache and return an iterable of the
        expired `(key, value)` pairs.

        )r   r   rm   r   r   rD   r   r   r   r<   r{   )	r   r   r   r   linksr   ri   r   rm   s	            r   r   zTTLCache.expire  s    
 <::<<D{y))$t|(;(;NNDHmmD$(&C&CDEEEM$)))dh9DKKMMMD $t|(;(; r   c                 F   | j         5 }|                     |           	 t          t          | j                            }||                     |          fcddd           S # t          $ r& t          dt          |           j	        z            dw xY w# 1 swxY w Y   dS zmRemove and return the `(key, value)` pair least recently used that
        has not already expired.

        Nrl   )
r   r   rm   rI   r   r   rn   r9   r4   r    r   r   r<   s      r   r?   zTTLCache.popitem      
 Z 	,4KK,4--.. TXXc]]+	, 	, 	, 	, 	, 	, 	, 	, ! N N N}tDzz/BBCCMN		, 	, 	, 	, 	, 	, 	, 	, 	, 	,(   B!A# B#0BBBBc                 T    | j         |         }| j                             |           |S r   )r   rd   r   r<   r@   s      r   	__getlinkzTTLCache.__getlink  )    S!  %%%r   r   )r    r!   r"   r#   r}   r   r   r0   rF   r   r   r   rD   rJ   r  r[   r   r   r?   r   r   r   r   r   r     s-       JJ         ,0>T    / / / .3-> 
, 
, 
, 
, 5:4E % % % % .3->          " " "   X   ,, , ,    r   r   c                       e Zd ZdZdZej         G d d                      Zej	        dfdZ
d Zej        fdZej        fd	Zej        fd
Zd Zed             ZddZd Zd ZdS )r   z;Time aware Least Recently Used (TLRU) cache implementation.   c                        e Zd ZdZddZd ZdS )TLRUCache._Itemr<   r   removedNc                 0    || _         || _        d| _        d S r   r  r   s      r   r0   zTLRUCache._Item.__init__*  s    DH"DL DLLLr   c                 "    | j         |j         k     S r   r   )r   others     r   __lt__zTLRUCache._Item.__lt__/  s    <%-//r   r   )r    r!   r"   r$   r0   r  r   r   r   _Itemr  &  s<        1		! 	! 	! 	!
	0 	0 	0 	0 	0r   r  Nc                     t                               | |||           t          j                    | _        g | _        || _        d S r   )r   r0   r_   r`   _TLRUCache__items_TLRUCache__order_TLRUCache__ttu)r   r/   ttur   r(   s        r   r0   zTLRUCache.__init__2  s>    T7E9===".00


r   c                 z    	 | j         |         }|                                 |j        k     S # t          $ r Y dS w xY wr   )r  r   r   r9   )r   r<   items      r   rF   zTLRUCache.__contains__8  r   r   c                     	 |                      |          }|                                 |j        k      }n# t          $ r d}Y nw xY w|r|                     |          S  || |          S r   )_TLRUCache__getitemr   r   r9   r:   )r   r<   r   r"  r   s        r   r   zTLRUCache.__getitem__@  r   r   c                    | j         5 }|                     |||          }||k     s	 d d d            d S |                     |            || ||           d d d            n# 1 swxY w Y   	 d|                     |          _        n# t
          $ r Y nw xY wt                              ||          x| j        |<   }t          j
        | j        |           d S NT)r   r  r   r$  r  r9   r   r  r  heapqheappushr  )r   r<   r@   rf   r   r   r"  s          r   r   zTLRUCache.__setitem__L  sB   Z 	,4jjeT22G7NN	, 	, 	, 	, 	, 	, 	, 	, KKM$U+++	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	,	*.DNN3'' 	 	 	D	#,??3#@#@@SDt|T*****s(   A""A""A&)A&.B	 	
BBc                     | j         5 } || |           d d d            n# 1 swxY w Y   | j                            |          }d|_        ||j        k     st          |          d S r&  )r   r  r   r  r   r9   )r   r<   ri   r   r"  s        r   rD   zTLRUCache.__delitem__\  s    Z 	%4M$$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% |$$t|##3-- $#s   !%%c              #      K   | j         D ]<}| j        5 }||j        k     r|j        s	|j        V  d d d            n# 1 swxY w Y   =d S r   )r  r   r   r  r<   )r   r   r   s      r   rJ   zTLRUCache.__iter__e  s      L 	# 	#D #t$,&&t|&(NNN# # # # # # # # # # # # # # #	# 	#s   ;?	?	c                     | j         S )z1The local time-to-use function used by the cache.)r  r6   s    r   r   zTLRUCache.ttul  r  r   c                 ^   ||                                  }| j        }| j        }t          |          t          |          | j        z  k    r'd |D             x| _        }t          j        |           g }t          j        }t          j	        }|r|d         j
        s||d         j        k     st          j        |          }|j
        sD|                    |j         || |j                  f            || |j                   ||j        = |r|d         j
        n||d         j        k     |S )r  Nc                      g | ]}|j         	|S r   )r  ).0r"  s     r   
<listcomp>z$TLRUCache.expire.<locals>.<listcomp>|  s    #O#O#OT$,#OD#O#O#Or   r   )r   r  r  rL   _TLRUCache__HEAP_CLEANUP_FACTORr'  heapifyr   rD   r   r  r   heappopr   r<   )r   r   itemsorderr   ri   r   r"  s           r   r   zTLRUCache.expireq  s6   
 <::<<Du::E

T%????#O#OU#O#O#OODL5M%   )) 	$q) 	$$q9I2I2I=''D< $--dh*G*GHIIIdDH---$(O  	$q) 	$$q9I2I2I r   c                 F   | j         5 }|                     |           	 t          t          | j                            }||                     |          fcddd           S # t          $ r& t          dt          |           j	        z            dw xY w# 1 swxY w Y   dS r	  )
r   r   rm   rI   r  r   rn   r9   r4   r    r
  s      r   r?   zTLRUCache.popitem  r  r  c                 T    | j         |         }| j                             |           |S r   )r  rd   r  s      r   	__getitemzTLRUCache.__getitem  r  r   r   )r    r!   r"   r#   r0  	functoolstotal_orderingr  r   r   r0   rF   r   r   r   rD   rJ   r[   r   r   r?   r$  r   r   r   r   r   !  s2       EE	0 	0 	0 	0 	0 	0 	0 	0 ,0>T    / / / .3-> 
, 
, 
, 
, 5:4E + + + +  .3->        # # #   X   0, , ,    r   r   	CacheInfo)hitsmissesr/   rX   Fc                 2     ddl m  fd}|S )z_Decorator to wrap a function with a memoizing callable that saves
    results in a cache.

    r   _wrapperc                     rTt          t                    rfd}n(t          t          j        j                  rfd}nd } | |          S  |           S )Nc                 <    t          | |j        j                  S r   )
_CacheInfor/   rX   r;  r<  caches     r   	make_infoz,cached.<locals>.decorator.<locals>.make_info  s    %dFEM5>RRRr   c                 B    t          | |d t                              S r   )rB  rL   rC  s     r   rE  z,cached.<locals>.decorator.<locals>.make_info  s    %dFD#e**EEEr   c                 &    t          | |dd          S r'   )rB  )r;  r<  s     r   rE  z,cached.<locals>.decorator.<locals>.make_info  s    %dFAq999r   info)
isinstancer   r_   abcMapping)funcrE  r?  rD  	conditionrI  r<   locks     r   	decoratorzcached.<locals>.decorator  s     	?%'' :S S S S S S E;?#:;; :F F F F F F
: : : 8D%dIINNNN8D%dI>>>r   )_cachedr?  rD  r<   rO  rN  rI  rP  r?  s   ````` @r   r	   r	     sV    
 "!!!!!? ? ? ? ? ? ? ? ? ?* r   c                 2     ddl m  fd}|S )zoDecorator to wrap a class or instance method with a memoizing
    callable that saves results in a cache.

    r   r>  c                 N    rd } | |          S  |           S )Nc                     t          | t                    rt          ||| j        | j                  S t          | t
          j        j                  rt          ||d t          |                     S t          d          )Nz)cache(self) must return a mutable mapping)
rJ  r   rB  r/   rX   r_   rK  rL  rL   	TypeError)rD  r;  r<  s      r   rE  z2cachedmethod.<locals>.decorator.<locals>.make_info  sn    eU++ Q%dFEM5>RRR{'>?? Q%dFD#e**EEE#$OPPPr   rH  r   )methodrE  r?  rD  rN  rI  r<   rO  s     r   rP  zcachedmethod.<locals>.decorator  sU     	AQ Q Q 8FE3iiPPPP8FE3i@@@r   )_cachedmethodr?  rR  s   ````` @r   r
   r
     s`    
 ('''''A A A A A A A A A A r   )r#   __all____version__r_   collections.abcr8  r'  r   r    r   r   rK  MutableMappingr   r   r   r   r   r   r   r   
namedtuplerB  hashkeyr	   	methodkeyr
   r   r   r   <module>ra     s   6 6
                             i i i i iKO* i i iX( ( ( ( ( ( ( (8K! K! K! K! K!u K! K! K!\#% #% #% #% #%u #% #% #%L$( $( $( $( $(e $( $( $(NG; G; G; G; G;% G; G; G;TD D D D D{ D D DNy y y y y y y yx $[#::: 

 lE    > !NE      r   