o
    ™©ZhZ  ã                   @   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d	ed
df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   sd   | rt  ¡ D ]}| ¡  qt ¡  dS t  ¡ D ]}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   úA/var/www/html/lang_env/lib/python3.10/site-packages/jedi/cache.pyÚclear_time_caches   s   	
€ýþr   c                    ó   ‡ 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~   ˆ| i |¤Ž}t |ƒ}zˆ | \}}|t ¡ kr|W S W n	 ty%   Y nw t |ƒ}ttˆƒ}|d ur=t ¡ | |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                    r   )Nc                    s.   i ‰ t ˆƒ‡ ‡‡fdd„ƒ}‡ fdd„|_|S )Nc                     sl   | t | ¡ ƒf}zˆ | \}}t ¡ |ˆ k r|W S W n	 ty$   Y nw ˆ| i |¤Ž}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>`   s    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y4   ˆ | g|¢R i |¤Ž}|||< | Y S w )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    $ 