U
    2tco                     @   sD  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k
r\   ddl	mZ Y nX 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ddddg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   s   d S N selfr   r   3/tmp/pip-unpacked-wheel-7ofpm20j/cachetools/func.pyr      s    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   s   d S r   r   r   r   r   r   r   ,   s    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   | |}V z* | }d  d7  < |W W  5 Q R  S  t k
r^   d  d7  < Y nX W 5 Q R X | |}z*  ||W  5 Q R  W S Q R X W n tk
r   | Y S X d S )Nr   r   )KeyError
setdefault
ValueError)argskwargskv)cachefunckeylockstatsr   r   wrapper9   s    
 
$z*_cache.<locals>.decorator.<locals>.wrapperc               	      s2    \} } j } j}W 5 Q R X t| |||S r   )r   r   
_CacheInfo)r   r   r   r   r-   r0   r1   r   r   
cache_infoJ   s
    z-_cache.<locals>.decorator.<locals>.cache_infoc                      s4   & z    W 5 ddgd d < X W 5 Q R X d S )Nr   )clearr   r4   r   r   cache_clearQ   s    z._cache.<locals>.decorator.<locals>.cache_clearc                      s
    dS )Nr   typedr   r   r8   r   r   <lambda>Z       z+_cache.<locals>.decorator.<locals>.<lambda>)	r   ZtypedkeyZhashkeyr   r5   r7   Zcache_parameters	functoolsupdate_wrapper)r.   r2   r5   r7   r-   r   r9   )r.   r/   r0   r1   r   	decorator4   s    z_cache.<locals>.decorator)r   )r-   r9   r?   r   r>   r   _cache1   s    *r@      Fc                 C   s@   | dkrt t |S t| r.t td|| S t t| |S d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.

    NrA   )r@   r   callabler   r8   r   r   r   
fifo_cachea   s
    rC   c                 C   s@   | dkrt t |S t| r.t td|| S t t| |S dS )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Least Frequently Used (LFU)
    algorithm.

    NrA   )r@   r   rB   r   r8   r   r   r   r   o   s
    r   c                 C   s@   | dkrt t |S t| r.t td|| S t t| |S dS )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Least Recently Used (LRU)
    algorithm.

    NrA   )r@   r   rB   r   r8   r   r   r   r   }   s
    r   c                 C   s@   | dkrt t |S t| r.t td|| S t t| |S dS )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Most Recently Used (MRU)
    algorithm.
    NrA   )r@   r   rB   r   r8   r   r   r   r      s
    r   c                 C   sD   | dkrt t |S t| r0t td||| S t t| ||S dS )zDecorator to wrap a function with a memoizing callable that saves
    up to `maxsize` results based on a Random Replacement (RR)
    algorithm.

    NrA   )r@   r   rB   r	   )r   choicer9   r   r   r   r      s
    r   iX  c                 C   sL   | dkrt t|||S t| r6t td|||| S t t| |||S d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.
    NrA   )r@   r    rB   r
   )r   r$   r%   r9   r   r   r   r      s
    r   )rA   F)rA   F)rA   F)rA   F)'__doc__collectionsr<   r"   randomtime	threadingr   ImportErrorZdummy_threading r   Zfifor   Zlfur   Zlrur   Zmrur   rrr	   r$   r
   __all__
namedtupler3   dictr   r    r@   rC   r   r   r   rD   r   	monotonicr   r   r   r   r   <module>   s<    

	0



