a
    lc!                     @   sX  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*d0d&d'Z+dS )1    N)Path)DictAnyiX  i ' !   z
%s-%s%s-%s   c                  C   sd   t   dkr(ttdpddd} n4t   dkrHtdddd} nttdpVd	d
} |  S )NwindowsLOCALAPPDATA~ZParsodarwinLibraryZCachesXDG_CACHE_HOMEz~/.cacheZparso)platformsystemlowerr   osgetenv
expanduser)Zdir_ r   G/var/www/html/django/DPS/env/lib/python3.9/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__)N)__name__
__module____qualname__r$   r   r   r   r   r   g   s   r   c              	   C   sl   |  }|du rdS z.t|  |j }||jkr@t |_|jW S W n$ tyf   t| |j||d Y S 0 dS )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    

r0   c              	   C   s   t | ||d}zn|tj|kr&W d S t|d:}t  zt|}W t	  n
t	  0 W d    n1 sp0    Y  W n t
y   Y d S 0 t| || td| |jS d S )Nr   rbzpickle loaded: %s)_get_hashed_pathr   r)   getmtimeopengcdisablepickleloadenableFileNotFoundError_set_cache_itemLOGdebugr   )r,   r)   r.   r   fr/   r   r   r   r+      s    6r+   c                    sf   t dd t D tkrRt 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>       z"_set_cache_item.<locals>.<genexpr>c                    s    i | ]\}}|j  kr||qS r   )r"   )r@   r)   Z	node_itemZcutoff_timer   r   
<dictcomp>   s   
z#_set_cache_item.<locals>.<dictcomp>)sumr   values_CACHED_SIZE_TRIGGERr    _CACHED_FILE_MINIMUM_SURVIVALitems
setdefault)r,   r)   r/   keyZpath_to_item_mapr   rD   r   r;      s    
r;   Tc           	      C   s   |j }z|d u rd n| }W n ty8   d }d}Y n0 t|||}t| || |r|d urzt| |||d W n" ty   td| t	 Y n0 t
|d 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)	r,   r-   moduler   Zpicklingr   r)   r.   itemr   r   r   try_to_save_module   s"    

rV   c                 C   sH   t t| ||dd }t||tj W d    n1 s:0    Y  d S )Nr   wb)r4   r2   r7   dumpHIGHEST_PROTOCOL)r,   r)   rU   r   r>   r   r   r   rN      s    rN   c                 C   s"   | d u rt } t|  t  d S r   )r   shutilrmtreer   clearr   r   r   r   clear_cache   s    
r]   c              
   C   s   | d u rt } |  sdS t| D ]f}| |}| s:q"t|D ]B}| jt	 t

 krDzt|j W qD ty   Y qDY qD0 qDq"dS )NFT)r   existsr   listdirr   is_dirscandirstatst_atime_CACHED_FILE_MAXIMUM_SURVIVALr    remover)   rM   )r   Zinactivity_thresholddirnameZversion_pathfiler   r   r   clear_inactive_cache   s    
rh   c                 C   sZ   zt | d  W nD tyT   zt| d}|  W n ttfyN   Y Y dS 0 Y n0 dS )NaFT)r   utimer:   r4   closerM   IOError)r)   rg   r   r   r   _touch   s    
rm   c                 C   sd   t | d}ztj|}W n ty0   d }Y n0 |d u sJ|t t kr`t|sVdS t| d d S )Nr   F)	r   r   r)   r3   r:   _CACHE_CLEAR_THRESHOLDr    rm   rh   )r   Z	lock_pathZclear_lock_timer   r   r   rS      s    

rS   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)r,   r)   r   	directoryZ	file_hashr   r   r   r2     s    
r2   c                 C   s,   | d u rt } | t}| s(t| |S r   )r   r   _VERSION_TAGr^   r   makedirs)r   rv   r   r   r   ro     s    

ro   )N)N)N)TN)N)N)N)N)N),r    r   sysrp   r5   rZ   r   loggingrP   r7   pathlibr   typingr   r   	getLoggerr%   r<   rI   rd   rH   Z_PICKLE_VERSIONpython_implementationversion_inforw   r   r   rn   r   r   rr   __annotations__r   r0   r+   r;   rV   rN   r]   rh   rm   rS   r2   ro   r   r   r   r   <module>   sR   






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