
                         l   d Z ddlmZ ddlZddlZddl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dlmZ dZ ej0                  dg d      Z G d de      Z G d de      ZddZddZddZdej@                  dfdZ!ddedfdZ"y# e	$ r	 ddlmZ Y w xY w# e	$ r	 ddlmZ Y w xY w)z?`functools.lru_cache` compatible memoizing function decorators.    )absolute_importN)	monotonic)time)RLock   )keys)LFUCache)LRUCache)RRCache)TTLCache)	lfu_cache	lru_cacherr_cache	ttl_cache	CacheInfo)hitsmissesmaxsizecurrsizec                        e Zd ZdZed        Zy)_UnboundCacheNc                     t        |       S N)lenselfs    "lib/third_party/cachetools/func.pyr   z_UnboundCache.currsize#   s    t9    )__name__
__module____qualname__r   propertyr    r   r   r   r      s    ' r   r   c                   "    e Zd Zd Zed        Zy)_UnboundTTLCachec                 F    t        j                  | t        d      ||       y )Ninf)r   __init__float)r   ttltimers      r   r(   z_UnboundTTLCache.__init__*   s    dE%L#u5r   c                      y r   r#   r   s    r   r   z_UnboundTTLCache.maxsize-   s    r   N)r   r    r!   r(   r"   r   r#   r   r   r%   r%   (   s    6  r   r%   Fc                       fd}|S )Nc                     rt         j                  nt         j                  t               ddgfd}fd} fd}t	        j
                  |        t        |d      s |_        ||_        ||_	        |S )Nr   c                      5  \  } }j                   }j                  }d d d        t               S # 1 sw Y   xY wr   )r   r   
_CacheInfo)r   r   r   r   cachelockstatss       r   
cache_infoz-_cache.<locals>.decorator.<locals>.cache_info9   sA    f-->>  fgx88	 4s	   8Ac                  ~    5  	  j                          ddgd d  	 d d d        y # ddgd d  w xY w# 1 sw Y   y xY w)Nr   )clear)r1   r2   r3   s   r   cache_clearz._cache.<locals>.decorator.<locals>.cache_clear@   sA    	
++-V%(	 4 V%(	 4s   3'3	03<c                  *    | i |}5  	 |   }dxx   dz  cc<   |cd d d        S # t         $ r dxx   dz  cc<   Y nw xY w	 d d d        n# 1 sw Y   nxY w | i |}	 5  ||<   d d d        |S # 1 sw Y   |S xY w# t        $ r Y |S w xY w)Nr   r   )KeyError
ValueError)	argskwargskvr1   funckeyr2   r3   s	       r   wrapperz*_cache.<locals>.decorator.<locals>.wrapperG   s    
t
v
a	Ah!
(a-(	 4
  	
(a-(	
 44 

a%(  h	  h  hsV   A+AAAAA&B (A8.B 8B=B B 	BB__wrapped__)
r   typedkeyhashkeyr   	functoolsupdate_wrapperhasattrrB   r4   r7   )	r?   r4   r7   rA   r@   r2   r3   r1   typeds	   `   @@@r   	decoratorz_cache.<locals>.decorator4   sq     $--dllC7DFE9 " Wd+7M* g#G%GNr   r#   )r1   rH   rI   s   `` r   _cacherJ   2   s    )V 
r      c                 X    | t        t               |      S t        t        |       |      S )zDecorator to wrap a function with a memoizing callable that saves

    up to `maxsize` results based on a Least Frequently Used (LFU)
    algorithm.

    )rJ   r   r	   r   rH   s     r   r   r   b   *     _-/5))(7#U++r   c                 X    | t        t               |      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.

    )rJ   r   r
   rM   s     r   r   r   o   rN   r   c                 Z    | t        t               |      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.

    )rJ   r   r   )r   choicerH   s      r   r   r   |   s,     _-/5))''6*E22r   iX  c                 `    | t        t        ||      |      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.
    )rJ   r%   r   )r   r*   r+   rH   s       r   r   r      s4     _"3.66(7C/77r   )F)rK   F)#__doc__
__future__r   collectionsrE   randomr   r   default_timerImportError	threadingr   dummy_threading r   lfur	   lrur
   rrr   r*   r   __all__
namedtupler0   dictr   r%   rJ   r   r   rQ   r   r   r#   r   r   <module>rb      s    E &   )-$     
=#[##K$MO
D x -`
,
, e 
3 s-u 	8}  )()
  $#$s"   B B% B"!B"%B32B3