U
    nufZ  ã                   @   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   sb   | r$t  ¡ D ]}| ¡  qt ¡  n:t  ¡ D ]0}t| ¡ ƒD ]\}\}}|t ¡ k r<||= q<q,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   ú./tmp/pip-unpacked-wheel-ol4ehs9f/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                     s|   ˆ| |Ž}t |ƒ}z"ˆ | \}}|t ¡ kr2|W S W n tk
rH   Y nX t |ƒ}ttˆƒ}|d k	rxt ¡ | |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                     sj   | t | ¡ ƒf}z&ˆ | \}}t ¡ |ˆ k r4|W S W n tk
rJ   Y nX ˆ| |Ž}t ¡ |fˆ |< |S r   )Ú	frozensetr   r   r   )r   r   r   ÚcreatedÚresult)r   ÚfuncÚsecondsr   r   r"   S   s    

z.time_cache.<locals>.decorator.<locals>.wrapperc                      s   ˆ   ¡ S r   )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    r0   c                    s   t ˆ ƒ‡ fdd„ƒ}|S )zA normal memoize function.c                    sj   | j  di ¡}| ˆ i ¡}|t| ¡ ƒf}z
|| W S  tk
rd   ˆ | f|ž|Ž}|||< | Y 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>.wrapperr   )r5   r"   r   r4   r   Úmemoize_methodf   s    
r6   )F)Ú__doc__r   Ú	functoolsr   Útypingr   r   r   Zjedir   Zparso.cacher   r	   ÚstrÚfloatÚ__annotations__Úboolr   r%   r0   r6   r   r   r   r   Ú<module>   s   $ 