B
    /‹dZ  ã               @   s˜   U d Z ddlZddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZ i aeeeeeeef f f ed< dedd	œd
d„Zdd„ Zdd„ Zdd„ ZdS )a7  
This caching is very important for speed and memory optimizations. There's
nothing really spectacular, just some decorators. The following cache types are
available:

- ``time_cache`` can be used to cache something for just a limited time span,
  which can be useful if there's user interaction and the user cannot react
  faster than a certain time.

This module is one of the reasons why |jedi| is not thread-safe. As you can see
there are global variables, which are holding the cache information. Some of
these variables are being cleaned after every API usage.
é    N)Úwraps)ÚAnyÚDictÚTuple)Úsettings)Úparser_cacheÚ_time_cachesF)Ú
delete_allÚreturnc             C   sn   | r(xt  ¡ D ]}| ¡  qW t ¡  nBx@t  ¡ D ]4}x.t| ¡ ƒD ]\}\}}|t ¡ k rD||= qDW q2W dS )zê Jedi caches many things, that should be completed after each completion
    finishes.

    :param delete_all: Deletes also the cache that is normally not deleted,
        like parser cache, which is important for faster parsing.
    N)r   ÚvaluesÚclearr   ÚlistÚitemsÚtime)r	   ÚcacheZtcÚkeyÚtÚvalue© r   úW/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/jedi/cache.pyÚclear_time_caches   s    	
r   c                s   ‡ fdd„}|S )a\  
    This decorator works as follows: Call it with a setting and after that
    use the function with a callable that returns the key.
    But: This function is only called if the key is not available. After a
    certain amount of time (`time_add_setting`) the cache is invalid.

    If the given key is None, the function will not be cached.
    c                s    i ‰ ˆ t ˆ< ‡ ‡‡fdd„}|S )Nc                 sz   ˆ| |Ž}t |ƒ}y ˆ | \}}|t ¡ kr0|S W n tk
rF   Y nX t |ƒ}ttˆƒ}|d k	rvt ¡ | |fˆ |< |S )N)Únextr   ÚKeyErrorÚgetattrr   )ÚargsÚkwargsÚ	generatorr   Zexpiryr   Ztime_add)ÚdctÚkey_funcÚtime_add_settingr   r   Úwrapper<   s    

z4signature_time_cache.<locals>._temp.<locals>.wrapper)r   )r   r    )r   )r   r   r   Ú_temp8   s    z#signature_time_cache.<locals>._tempr   )r   r!   r   )r   r   Úsignature_time_cache/   s    	r"   c                s   ‡ fdd„}|S )Nc                s.   i ‰ t ˆƒ‡ ‡‡fdd„ƒ}‡ fdd„|_|S )Nc                 sh   | t | ¡ ƒf}y$ˆ | \}}t ¡ |ˆ k r2|S W n tk
rH   Y nX ˆ| |Ž}t ¡ |fˆ |< |S )N)Ú	frozensetr   r   r   )r   r   r   ÚcreatedÚresult)r   ÚfuncÚsecondsr   r   r    S   s    
z.time_cache.<locals>.decorator.<locals>.wrapperc                  s   ˆ   ¡ S )N)r   r   )r   r   r   Ú<lambda>`   ó    z/time_cache.<locals>.decorator.<locals>.<lambda>)r   Úclear_cache)r&   r    )r'   )r   r&   r   Ú	decoratorP   s    ztime_cache.<locals>.decoratorr   )r'   r+   r   )r'   r   Ú
time_cacheO   s    r,   c                s   t ˆ ƒ‡ fdd„ƒ}|S )zA normal memoize function.c                sd   | j  di ¡}| ˆ i ¡}|t| ¡ ƒf}y|| S  tk
r^   ˆ | f|ž|Ž}|||< |S X d S )NZ_memoize_method_dct)Ú__dict__Ú
setdefaultr#   r   r   )Úselfr   r   Z
cache_dictr   r   r%   )Úmethodr   r   r    h   s    zmemoize_method.<locals>.wrapper)r   )r0   r    r   )r0   r   Úmemoize_methodf   s    r1   )F)Ú__doc__r   Ú	functoolsr   Útypingr   r   r   Zjedir   Zparso.cacher   r   ÚstrÚfloatÚ__annotations__Úboolr   r"   r,   r1   r   r   r   r   Ú<module>   s   $ 