
    f                       d dl mZ d dlmZ d dlmZ d dlmZmZm	Z	m
Z
mZmZmZmZ g dZ ede      Z ed      Z G d	 d
e
eef         Z edeedf         Z ed      Z G d de	eef         Z ededef         ZdddZy)    )annotations)deque)wraps)AnyCallableDictGenericHashableTupleTypeVarcast)SimpleCacheFastDictCachememoized_T)bound_Uc                  *    e Zd ZdZdddZddZd	dZy)
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                L    |dkD  sJ i | _         t               | _        || _        y Nr   )_datar   _keysmaxsize)selfr   s     O/var/www/cvtools/html/venv/lib/python3.12/site-packages/prompt_toolkit/cache.py__init__zSimpleCache.__init__   s%    {{#%
 %
#    c                T   	 | j                   |   S # t        $ r  |       }|| j                   |<   | j                  j                  |       t	        | j                         | j
                  kD  r5| j                  j                         }|| j                   v r| j                   |= |cY S w xY w)z
        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   getzSimpleCache.get    s    	::c?" 	ME#DJJsOJJc" 4::- $

 2 2 4 DJJ.

=1L	s    BB'&B'c                0    i | _         t               | _        y)zClear cache.N)r   r   r   )r   s    r   clearzSimpleCache.clear7   s    
W
r   N)   )r   intreturnNone)r#   r   r$   zCallable[[], _U]r,   r   )r,   r-   )__name__
__module____qualname____doc__r   r'   r)    r   r   r   r      s    $.r   r   _K._Vc                  "    e Zd ZdZdddZddZy)r   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.
    c                L    |dkD  sJ t               | _        || _        || _        y r   )r   r   	get_valuesize)r   r7   r8   s      r   r   zFastDictCache.__init__V   s$    axx %
"	r   c                    t        |       | j                  kD  r!| j                  j                         }|| v r| |=  | j                  | }|| |<   | j                  j                  |       |S N)r!   r8   r   r"   r7   r    )r   r#   r&   results       r   __missing__zFastDictCache.__missing__]   sd    t9tyy  JJ..0M$'%S	

#r   N)i@B )r7   zCallable[..., _V]r8   r+   r,   r-   )r#   r3   r,   r4   )r.   r/   r0   r1   r   r<   r2   r   r   r   r   A   s    
(
r   r   _Fc                     d fd}|S )zI
    Memoization decorator for immutable classes and pure functions.
    c                j     t              t               d fd       }t        t        |      S )N)r   c                      d fd} t        t        j                                     f}j                  ||      S )Nc                       i S r:   r2   )akwobjs   r   
create_newzEmemoized.<locals>.decorator.<locals>.new_callable.<locals>.create_neww   s    A}}$r   )r,   r   )tuplesorteditemsr'   )rB   rC   rE   r#   cacherD   s   ``  r   new_callablez1memoized.<locals>.decorator.<locals>.new_callableu   s5    % eF288:./0C99S*--r   )rB   r   rC   r   r,   r   )r   r   r   r=   )rD   rJ   rI   r   s   ` @r   	decoratorzmemoized.<locals>.decoratorr   s2    ,7,H	s	. 
	. B%%r   )rD   r=   r,   r=   r2   )r   rK   s   ` r   r   r   m   s    
& r   N)i   )r   r+   r,   zCallable[[_F], _F])
__future__r   collectionsr   	functoolsr   typingr   r   r   r	   r
   r   r   r   __all__r   r   r   r3   r4   r   objectr=   r   r2   r   r   <module>rR      s    "   O O O T"T])'"b&/ )X Tx}-.T]&DRL &R T#v+./r   