
    H                     b    S SK Jr  S SKJr  S SKJr  Sr " S S\5      r " S S\	5      r
SS	 jrg
)    )unicode_literals)dequewraps)SimpleCacheFastDictCachememoizedc                   .    \ rS rSrSrSS jrS rS rSrg)	r      z
Very simple cache that discards the oldest item when the cache size is
exceeded.

:param maxsize: Maximum size of the cache. (Don't make it too big.)
c                 v    [        U[        5      (       a  US:  d   e0 U l        [        5       U l        Xl        g Nr   )
isinstanceint_datar   _keysmaxsize)selfr   s     'lib/third_party/prompt_toolkit/cache.py__init__SimpleCache.__init__   s0    '3''GaK77
W
    c                 X    U R                   U   $ ! [         a    U" 5       nX0R                   U'   U R                  R                  U5        [	        U R                   5      U R
                  :  a6  U R                  R                  5       nX@R                   ;   a  U R                   U	 Us $ f = f)zz
Get object from the cache.
If not found, call `getter_func` to resolve it, and put that on the top
of the cache instead.
)r   KeyErrorr   appendlenr   popleft)r   keygetter_funcvaluekey_to_removes        r   getSimpleCache.get   s    	::c?" 	ME#JJsOJJc" 4::- $

 2 2 4 JJ.

=1L	s    BB)(B)c                 0    0 U l         [        5       U l        g)zClear cache. N)r   r   r   )r   s    r   clearSimpleCache.clear1   s    
W
r   )r   r   r   N)   )	__name__
__module____qualname____firstlineno____doc__r   r!   r$   __static_attributes__ r   r   r   r      s    .r   r   c                   (    \ rS rSrSrSS jrS rSrg)r   7   a  
Fast, lightweight cache which keeps at most `size` items.
It will discard the oldest items in the cache first.

The cache is a dictionary, which doesn't keep track of access counts.
It is perfect to cache little immutable objects which are not expensive to
create, but where a dictionary lookup is still much faster than an object
instantiation.

:param get_value: Callable that's called in case of a missing key.
Nc                     [        U5      (       d   e[        U[        5      (       a  US:  d   e[        5       U l        Xl        X l        g r   )callabler   r   r   r   	get_valuesize)r   r2   r3   s      r   r   FastDictCache.__init__K   s?    	""""$$$11W
"	r   c                     [        U 5      U R                  :  a!  U R                  R                  5       nX ;   a  X	 U R                  " U6 nX0U'   U R                  R                  U5        U$ N)r   r3   r   r   r2   r   )r   r   r    results       r   __missing__FastDictCache.__missing__S   s\    t9tyy  JJ..0M$'%S	

#r   )r   r2   r3   )Ni@B )r'   r(   r)   r*   r+   r   r8   r,   r-   r   r   r   r   7   s    
&
r   r   c                 &   ^ [        U S9mU4S jnU$ )zA
Momoization decorator for immutable classes and pure functions.
)r   c                 4   >^  [        T 5      UU 4S j5       nU$ )Nc                  p   >^ ^ U UU4S jnT [        TR                  5       5      4nTR                  X25      $ )Nc                     > T" T 0 TD6$ r6   r-   )akwobjs   r   
create_newEmemoized.<locals>.decorator.<locals>.new_callable.<locals>.create_newi   s    A}}$r   )tupleitemsr!   )r>   r?   rA   r   cacher@   s   ``  r   new_callable1memoized.<locals>.decorator.<locals>.new_callableg   s.    % eBHHJ'(C99S--r   r   )r@   rF   rE   s   ` r   	decoratormemoized.<locals>.decoratorf   s!    	s	. 
	. r   )r   )r   rH   rE   s     @r   r	   r	   `   s     (E r   N)i   )
__future__r   collectionsr   	functoolsr   __all__objectr   dictr   r	   r-   r   r   <module>rP      s4    '  (& (V&D &Rr   