
    J                        d Z ddlm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ZdZ e ej&                  d d       d      rej&                  Znd Zej*                  dfdZej*                  dfdZy)z0Extensible memoizing collections and decorators.    )absolute_importN   )keys)Cache)LFUCache)LRUCache)RRCache)TTLCache)r   r   r   r	   r
   cachedcachedmethodz3.1.1c                      |        S N )fs    &lib/third_party/cachetools/__init__.py<lambda>r      s    ac    c                       y)N*   r   r   r   r   r   r      s    2r   __wrapped__c                 @    t        j                  | |       || _        | S r   )	functoolsupdate_wrapperr   )wrapperwrappeds     r   _update_wrapperr      s    Wg.!GNr   c                       fd}|S )z`Decorator to wrap a function with a memoizing callable that saves

    results in a cache.

    c                 R      fd}n fd}n fd}t        |       S )Nc                       | i |S r   r   )argskwargsfuncs     r   r   z*cached.<locals>.decorator.<locals>.wrapper'   s    T$V$$r   c                  ~     | i |}	 |   S # t         $ r Y nw xY w | i |}	 ||<   |S # t        $ r Y |S w xY wr   KeyError
ValueError)r    r!   kvcacher"   keys       r   r   z*cached.<locals>.decorator.<locals>.wrapper+   so      	q/ 	
	$!&!	%(   	
	s    	/ 	<<c                       | i |}	 5  |   cd d d        S # 1 sw Y   nxY wn# t         $ r Y nw 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r   r$   )r    r!   r'   r(   r)   r"   r*   locks       r   r   z*cached.<locals>.decorator.<locals>.wrapper9   s      	8 ttt 	
	$!&!	E!H  	    	
	sL   ) 	) %) 	55A  A	A  AA  A   	A-,A-r   )r"   r   r)   r*   r,   s   ` r   	decoratorzcached.<locals>.decorator$   s+    }%	 7D))r   r   r)   r*   r,   r.   s   ``` r   r   r      s    $*L 
r   c                       fd}|S )zpDecorator to wrap a class or instance method with a memoizing

    callable that saves results in a cache.

    c                 B      fd}n fd}t        |       S )Nc                      |       }| | g|i |S  |i |}	 ||   S # t         $ r Y nw xY w | g|i |}	 |||<   |S # t        $ r Y |S w xY wr   r$   )	selfr    r!   cr'   r(   r)   r*   methods	         r   r   z0cachedmethod.<locals>.decorator.<locals>.wrapperW   s    $K9.t.v.
.  	1+ 	
	4)$)&)	!A$   	
	s   & 	22A	 		AAc                 ,    |       }| 	| g|i |S  |i |}	  |       5  ||   cd d d        S # 1 sw Y   nxY wn# t         $ r Y nw xY w 	| g|i |}	  |       5  |||<   d d d        |S # 1 sw Y   |S xY w# t        $ r Y |S w xY wr   r$   )
r3   r    r!   r4   r'   r(   r)   r*   r,   r5   s
         r   r   z0cachedmethod.<locals>.decorator.<locals>.wrapperh   s    $K9.t.v.
.  	DzQ4 zzz 	
	4)$)&)	DzAaD  	    	
	sT   A 8	A AA 	AA!B )A9/B 9B>B B 	BBr-   )r5   r   r)   r*   r,   s   ` r   r.   zcachedmethod.<locals>.decoratorT   s!    |"$ 7F++r   r   r/   s   ``` r   r   r   M   s    &,P 
r   )__doc__
__future__r   r    r   r)   r   lfur   lrur   rrr	   ttlr
   __all____version__hasattrr   r   hashkeyr   r   r   r   r   <module>rB      sy    6 &        
#9##M:>N,,/ ll -` !LLt /r   