o
    ˷e!                     @   sd  U d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZ d dlmZmZ eeZdZ	 dZ	 dZ	 dZ	 de ejd  ejd ef Z	 d	d
 Ze Z	 dZd(ddZi Zeeef ed< G dd dZ d(ddZ!d(ddZ"dd Z#d)ddZ$d(ddZ%d(ddZ&defddZ'd d! Z(d(d"d#Z)d(d$d%Z*d(d&d'Z+dS )*    N)Path)DictAnyiX  i ' !   z
%s-%s%s-%s   c                  C   sp   t   dkrttdpddd} |  S t   dkr*tdddd} |  S ttdp1d	d
} |  S )NwindowsLOCALAPPDATA~ParsodarwinLibraryCachesXDG_CACHE_HOMEz~/.cacheparso)platformsystemlowerr   osgetenv
expanduser)dir_ r   B/var/www/ideatree/venv/lib/python3.10/site-packages/parso/cache.py_get_default_cache_pathB   s   r   iQ c                 C   s   | pt } | dS )z
    The path where the cache lock is stored.

    Cache lock will prevent continous cache clearing and only allow garbage
    collection once a day (can be configured in _CACHE_CLEAR_THRESHOLD).
    zPARSO-CACHE-LOCK)_default_cache_pathjoinpath
cache_pathr   r   r   _get_cache_clear_lock_pathY   s   
r   parser_cachec                   @   s   e Zd ZdddZdS )_NodeCacheItemNc                 C   s,   || _ || _|d u rt }|| _|| _d S N)nodelinestimechange_time	last_used)selfr"   r#   r%   r   r   r   __init__h   s   
z_NodeCacheItem.__init__r!   )__name__
__module____qualname__r(   r   r   r   r   r    g   s    r    c              	   C   sj   |  }|du r
dS zt|  |j }||jkr t |_|jW S W dS  ty4   t| |j||d Y S w )z0
    Returns a module or None, if it fails.
    Nr   )	get_last_modifiedr   pathr%   r$   r&   r"   KeyError_load_from_file_system)hashed_grammarfile_ior   p_timemodule_cache_itemr   r   r   load_moduleq   s"   


r4   c              	   C   s   t | ||d}z7|tj|krW d S t|d}t  zt|}W t	  nt	  w W d    n1 s8w   Y  W n
 t
yH   Y d S w t| || td| |jS )Nr   rbzpickle loaded: %s)_get_hashed_pathr   r-   getmtimeopengcdisablepickleloadenableFileNotFoundError_set_cache_itemLOGdebugr"   )r0   r-   r2   r   fr3   r   r   r   r/      s"   r/   c                    sf   t dd t D tkr)t t  t D ]\}} fdd| D t|< q|t| i |< d S )Nc                 s   s    | ]}t |V  qd S r!   )len).0vr   r   r   	<genexpr>   s    z"_set_cache_item.<locals>.<genexpr>c                    s    i | ]\}}|j  kr||qS r   )r&   )rD   r-   	node_itemcutoff_timer   r   
<dictcomp>   s
    
z#_set_cache_item.<locals>.<dictcomp>)sumr   values_CACHED_SIZE_TRIGGERr$   _CACHED_FILE_MINIMUM_SURVIVALitems
setdefault)r0   r-   r3   keypath_to_item_mapr   rH   r   r?      s   
r?   Tc           	      C   s   |j }z|d u r
d n| }W n ty   d }d}Y nw t|||}t| || |rS|d urUz
t| |||d W n tyK   td| t	 Y d S w t
|d d S d S d S )NFr   z6Tried to save a file to %s, but got permission denied.)r-   r,   OSErrorr    r?   _save_to_file_systemPermissionErrorwarningswarnWarning_remove_cache_and_update_lock)	r0   r1   moduler#   picklingr   r-   r2   itemr   r   r   try_to_save_module   s(   
	r]   c                 C   sJ   t t| ||dd}t||tj W d    d S 1 sw   Y  d S )Nr   wb)r8   r6   r;   dumpHIGHEST_PROTOCOL)r0   r-   r\   r   rB   r   r   r   rT      s   "rT   c                 C   s"   | d u rt } t|  t  d S r!   )r   shutilrmtreer   clearr   r   r   r   clear_cache   s   
rd   c              
   C   s   | d u rt } |  sdS t| D ]1}| |}| sqt|D ]}| jt	 t

 krAzt|j W q" ty@   Y q"w q"qdS )NFT)r   existsr   listdirr   is_dirscandirstatst_atime_CACHED_FILE_MAXIMUM_SURVIVALr$   remover-   rS   )r   inactivity_thresholddirnameversion_pathfiler   r   r   clear_inactive_cache   s$   
rq   c                 C   sX   z	t | d  W dS  ty+   zt| d}|  W Y dS  ttfy*   Y Y dS w w )NaFT)r   utimer>   r8   closerS   IOError)r-   rp   r   r   r   _touch   s   
rv   c                 C   sh   t | d}ztj|}W n ty   d }Y nw |d u s%|t t kr2t|s+dS t| d d S d S )Nr   F)	r   r   r-   r7   r>   _CACHE_CLEAR_THRESHOLDr$   rv   rq   )r   	lock_pathclear_lock_timer   r   r   rY      s   
rY   c                 C   s8   t |d}tt|d }tj|d| |f S )Nr   zutf-8z	%s-%s.pkl)	_get_cache_directory_pathhashlibsha256strencode	hexdigestr   r-   join)r0   r-   r   	directory	file_hashr   r   r   r6     s   
r6   c                 C   s,   | d u rt } | t}| st| |S r!   )r   r   _VERSION_TAGre   r   makedirs)r   r   r   r   r   rz     s   

rz   r!   )TN),r$   r   sysr{   r9   ra   r   loggingrV   r;   pathlibr   typingr   r   	getLoggerr)   r@   rN   rk   rM   _PICKLE_VERSIONpython_implementationversion_infor   r   r   rw   r   r   r}   __annotations__r    r4   r/   r?   r]   rT   rd   rq   rv   rY   r6   rz   r   r   r   r   <module>   s`   
 

	









