
    Mh                    V   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dS )    )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dS )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.)
       maxsizeintreturnNonec                X    |dk    sJ i | _         t                      | _        || _        d S Nr   )_datar   _keysr   )selfr   s     T/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/prompt_toolkit/cache.py__init__zSimpleCache.__init__   s,    {{{{#%
 %
#    keyr   getter_funcCallable[[], _U]r   c                ,   	 | j         |         S # t          $ rz  |            }|| j         |<   | j                            |           t	          | j                   | j        k    r*| 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   r"   r#   valuekey_to_removes        r   getzSimpleCache.get    s    	:c?" 	 	 	KMME#DJsOJc""" 4:-- $
 2 2 4 4 DJ..
=1LLL	s    BBBc                :    i | _         t                      | _        dS )zClear cache.N)r   r   r   )r   s    r   clearzSimpleCache.clear7   s    
WW


r!   N)r   )r   r   r   r   )r"   r   r#   r$   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dS )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.
    @B 	get_valueCallable[..., _V]sizer   r   r   c                X    |dk    sJ t                      | _        || _        || _        d S r   )r   r   r8   r:   )r   r8   r:   s      r   r    zFastDictCache.__init__V   s,    axxxx %
"			r!   r"   r4   r5   c                    t          |           | j        k    r | j                                        }|| v r| |=  | j        | }|| |<   | j                            |           |S N)r(   r:   r   r)   r8   r'   )r   r"   r+   results       r   __missing__zFastDictCache.__missing__]   sm    t99ty   J..00M$$'%S	
#r!   N)r7   )r8   r9   r:   r   r   r   )r"   r4   r   r5   )r/   r0   r1   r2   r    r?   r3   r!   r   r   r   A   sK        
 
(    
 
 
 
 
 
r!   r   _F   r   r   r   Callable[[_F], _F]c                     d fd}|S )zI
    Memoization decorator for immutable classes and pure functions.
    objr@   r   c                     t                    t                     d fd            }t          t          |          S )N)r   ar   kwr   c                      d fd} t          t                                                              f}                    ||          S )Nr   r   c                       i S r=   r3   )rF   rG   rD   s   r   
create_newzEmemoized.<locals>.decorator.<locals>.new_callable.<locals>.create_neww   s    sA}}}$r!   )r   r   )tuplesorteditemsr,   )rF   rG   rJ   r"   cacherD   s   ``  r   new_callablez1memoized.<locals>.decorator.<locals>.new_callableu   se    % % % % % % % % eF288::..//0C99S*---r!   )rF   r   rG   r   r   r   )r   r   r   r@   )rD   rO   rN   r   s   ` @r   	decoratorzmemoized.<locals>.decoratorr   sZ    ,7,H,H,H	s	. 	. 	. 	. 	. 	. 
	. B%%%r!   )rD   r@   r   r@   r3   )r   rP   s   ` r   r   r   m   s)    
& & & & & & r!   N)rA   )r   r   r   rB   )
__future__r   collectionsr   	functoolsr   typingr   r   r   r	   r
   r   r   r   __all__r   r   r   r4   r5   r   objectr@   r   r3   r!   r   <module>rW      s   " " " " " "             O O O O O O O O O O O O O O O O O O O O   WT"""WT]]) ) ) ) )'"b&/ ) ) )X WTx}-...WT]]& & & & &DRL & & &R WT#v+.///      r!   