o
    ˷eF                     @   s  d Z dZddlZddlZddlZddlZddlZzddlmZ W n e	y/   ddl
mZ Y nw ddlmZmZmZmZmZmZ ddlmZ edg d	ZG d
d deZG dd deZdd ZdddZdddZdddZdddZdejdfddZddejdfddZ dS ) z?`functools.lru_cache` compatible memoizing function decorators.)
fifo_cache	lfu_cache	lru_cache	mru_cacherr_cache	ttl_cache    N)RLock   )	FIFOCacheLFUCacheLRUCacheMRUCacheRRCacheTTLCache)keys	CacheInfo)hitsmissesmaxsizecurrsizec                   @   s$   e Zd Zedd Zedd ZdS )_UnboundCachec                 C      d S N selfr   r   F/var/www/ideatree/venv/lib/python3.10/site-packages/cachetools/func.pyr         z_UnboundCache.maxsizec                 C   s   t | S r   )lenr   r   r   r   r      s   z_UnboundCache.currsizeN)__name__
__module____qualname__propertyr   r   r   r   r   r   r      s
    
r   c                   @   s    e Zd Zdd Zedd ZdS )_UnboundTTLCachec                 C   s   t | tj|| d S r   )r   __init__mathinf)r   ttltimerr   r   r   r$   $   s   z_UnboundTTLCache.__init__c                 C   r   r   r   r   r   r   r   r   '   r   z_UnboundTTLCache.maxsizeN)r   r    r!   r$   r"   r   r   r   r   r   r#   #   s    r#   c                    s    j  fdd}|S )Nc                    s   rt jnt jd t  fdd}fdd}fdd}||_||_fdd	|_t|  |S )
Nr   c               	      s   | i |}( z | }d7 |W W  d    S  t y)   d7 Y nw W d    n1 s4w   Y  | i |}z  ||W  d    W S 1 sUw   Y  W d S  tyg   | Y S w )Nr	   )KeyError
setdefault
ValueError)argskwargskv)cachefuncr   keylockr   r   r   wrapper4   s(   
(z*_cache.<locals>.decorator.<locals>.wrapperc                     s>     j }  j}W d    n1 sw   Y  t| |S r   )r   r   
_CacheInfo)r   r   r0   r   r3   r   r   r   
cache_infoF   s
   z-_cache.<locals>.decorator.<locals>.cache_infoc                	      sJ    z
    W d nd w W d    d S 1 sw   Y  d S )Nr   )clearr   r6   r   r   cache_clearL   s
   
"z._cache.<locals>.decorator.<locals>.cache_clearc                      s
    dS )Nr   typedr   r   r:   r   r   <lambda>V   s   
 z+_cache.<locals>.decorator.<locals>.<lambda>)	r   typedkeyhashkeyr   r7   r9   cache_parameters	functoolsupdate_wrapper)r1   r4   r7   r9   r0   r   r;   )r1   r   r2   r3   r   r   	decorator/   s   z_cache.<locals>.decorator)r   )r0   r;   rC   r   rB   r   _cache,   s   +rD      Fc                 C   <   | du r
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.

    NrE   )rD   r   callabler
   r:   r   r   r   r   ]   
   r   c                 C   rF   )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Least Frequently Used (LFU)
    algorithm.

    NrE   )rD   r   rG   r   r:   r   r   r   r   k   rH   r   c                 C   rF   )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Least Recently Used (LRU)
    algorithm.

    NrE   )rD   r   rG   r   r:   r   r   r   r   y   rH   r   c                 C   rF   )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Most Recently Used (MRU)
    algorithm.
    NrE   )rD   r   rG   r   r:   r   r   r   r      s
   r   c                 C   s@   | du r
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.

    NrE   )rD   r   rG   r   )r   choicer;   r   r   r   r      s
   r   iX  c                 C   sH   | du r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.
    NrE   )rD   r#   rG   r   )r   r'   r(   r;   r   r   r   r      s
   r   )rE   F)!__doc____all__collectionsr@   r%   randomtime	threadingr   ImportErrordummy_threading r
   r   r   r   r   r   r   
namedtupler5   dictr   r#   rD   r   r   r   r   rI   r   	monotonicr   r   r   r   r   <module>   s4     
	
1


