U
    ڲg                     @   s   d Z dZddlZddlZddlZzddlmZ W n  ek
rP   ddlmZ Y nX ddl	m
Z
mZmZmZmZmZ ddl	mZ ddl	m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)cached)keysc                   @   s    e Zd Zdd Zedd ZdS )_UnboundTTLCachec                 C   s   t | tj|| d S N)r   __init__mathinf)selfttltimer r   3/tmp/pip-unpacked-wheel-voax59lc/cachetools/func.pyr      s    z_UnboundTTLCache.__init__c                 C   s   d S r   r   )r   r   r   r   maxsize   s    z_UnboundTTLCache.maxsizeN)__name__
__module____qualname__r   propertyr   r   r   r   r   r      s   r   c                    s    fdd}|S )Nc                    s:   r
t jnt j}t |t dd| }fdd|_|S )NT)cachekeylockinfoc                      s
    dS )Nr   typedr   r   r%   r   r   <lambda>        z+_cache.<locals>.decorator.<locals>.<lambda>)r   ZtypedkeyZhashkeyr   r   Zcache_parameters)funcr"   wrapperr!   r   r&   r   r   	decorator   s    z_cache.<locals>.decoratorr   )r!   r   r&   r,   r   r+   r   _cache   s    r-      Fc                 C   sD   | dkrt i d|S t| r0t td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.

    Nr.   )r-   callabler
   r%   r   r   r   r   &   s
    r   c                 C   sD   | dkrt i d|S t| r0t td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.

    Nr.   )r-   r/   r   r%   r   r   r   r   4   s
    r   c                 C   sD   | dkrt i d|S t| r0t td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.

    Nr.   )r-   r/   r   r%   r   r   r   r   B   s
    r   c                 C   s^   ddl m} |dtdd | dkr.ti d|S t| rJttd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.
    r   )warnz@mru_cache is deprecated   )
stacklevelNr.   )warningsr0   DeprecationWarningr-   r/   r   )r   r&   r0   r   r   r   r   P   s    r   c                 C   sH   | dkrt i d|S t| r2t td|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.

    Nr.   )r-   r/   r   )r   choicer&   r   r   r   r   a   s
    r   iX  c                 C   sR   | dkrt t||d|S t| r:t td||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.
    Nr.   )r-   r   r/   r   )r   r   r   r&   r   r   r   r   o   s
    r   )r.   F)r.   F)r.   F)r.   F)__doc____all__r   randomtime	threadingr   ImportErrorZdummy_threading r
   r   r   r   r   r   r   r   r   r-   r   r   r   r   r5   r   	monotonicr   r   r   r   r   <module>   s&    	




