o
    tBho                     @   s>  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 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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.    N)RLock   )keys)	FIFOCache)LFUCache)LRUCache)MRUCache)RRCache)TTLCache)	lfu_cache	lru_cache	mru_cacherr_cache	ttl_cache	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/html/riverr-enterprise-integrations-main/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t ddg fdd}fdd}fdd}||_||_fdd	|_t|  |S )
Nr   c               	      s   | i |}0 z | }d  d7  < |W W  d    S  t y1   d  d7  < Y nw W d    n1 s<w   Y  | i |}z  ||W  d    W S 1 s]w   Y  W d S  tyo   | Y S w )Nr   r   )KeyError
setdefault
ValueError)argskwargskv)cachefunckeylockstatsr   r   wrapper9   s(   
(z*_cache.<locals>.decorator.<locals>.wrapperc                     sF    \} } j } j}W d    n1 sw   Y  t| |||S r   )r   r   
_CacheInfor   r0   r3   r4   r   r   
cache_infoJ   s   z-_cache.<locals>.decorator.<locals>.cache_infoc                      sZ   ! z    W ddgd d < n	ddgd d < w W d    d S 1 s&w   Y  d S )Nr   )clearr   r7   r   r   cache_clearQ   s
   
&"z._cache.<locals>.decorator.<locals>.cache_clearc                      s
    dS )Nr   typedr   r   r;   r   r   <lambda>Z   s   
 z+_cache.<locals>.decorator.<locals>.<lambda>)	r   typedkeyhashkeyr   r8   r:   cache_parameters	functoolsupdate_wrapper)r1   r5   r8   r:   r0   r   r<   )r1   r2   r3   r4   r   	decorator4   s   z_cache.<locals>.decorator)r   )r0   r<   rD   r   rC   r   _cache1   s   *rE      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.

    NrF   )rE   r   callabler   r;   r   r   r   
fifo_cachea   
   rI   c                 C   rG   )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Least Frequently Used (LFU)
    algorithm.

    NrF   )rE   r   rH   r   r;   r   r   r   r   o   rJ   r   c                 C   rG   )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Least Recently Used (LRU)
    algorithm.

    NrF   )rE   r   rH   r   r;   r   r   r   r   }   rJ   r   c                 C   rG   )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Most Recently Used (MRU)
    algorithm.
    NrF   )rE   r   rH   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.

    NrF   )rE   r   rH   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.
    NrF   )rE   r#   rH   r
   )r   r'   r(   r<   r   r   r   r      s
   r   )rF   F)'__doc__collectionsrA   r%   randomtime	threadingr   ImportErrordummy_threading r   fifor   lfur   lrur   mrur   rrr	   r'   r
   __all__
namedtupler6   dictr   r#   rE   rI   r   r   r   rK   r   	monotonicr   r   r   r   r   <module>   s>    
	
0


