o
    b	                  	   @   s  d Z ddlZddlZddlmZ ddlZddlmZmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ eZeZe
eef Zeeef ZeededZd	ed
efddZd	ed
efddZded
efddZdedee d
e
e	e e	e f fddZdedee d	ed
dfddZdS )z;Caching of formatted files with feature-based invalidation.    N)Path)DictIterableSetTuple)user_cache_dir)Mode)versionblackmodereturnc              
   C   s~   t | }| s
i S |d&}zt|}W n tjtfy,   i  Y W  d   S w W d   |S 1 s8w   Y  |S )zRead the cache if it exists and is well formed.

    If it is not well formed, the call to write_cache later should resolve the issue.
    rbN)get_cache_fileexistsopenpickleloadUnpicklingError
ValueError)r   
cache_fileZfobjcache r   J/var/www/secure340b-portal/env/lib/python3.10/site-packages/black/cache.py
read_cache   s   
r   c                 C   s   t d|   d S )Nzcache.z.pickle)	CACHE_DIRZget_cache_key)r   r   r   r   r   ,   s   r   pathc                 C   s   |   }|j|jfS )zKReturn the information used to check if a file is already formatted or not.)statst_mtimest_size)r   r   r   r   r   get_cache_info0   s   r   r   sourcesc                 C   sT   t  t  }}|D ]}| }| t|t|kr || q	|| q	||fS )zSplit an iterable of paths in `sources` into two sets.

    The first contains paths of files that modified on disk or are not in the
    cache. The other contains paths to non-modified files.
    )setresolvegetstrr   add)r   r    tododonesrcZres_srcr   r   r   filter_cached6   s   r)   c                 C   s   t |}z>tjddd i | dd |D }tjt|jdd}tj||dd W d	   n1 s4w   Y  t	
|j| W d	S  tyL   Y d	S w )
zUpdate the cache file.T)parentsexist_okc                 S   s   i | ]}t | t|qS r   )r$   r"   r   ).0r(   r   r   r   
<dictcomp>M   s    zwrite_cache.<locals>.<dictcomp>F)dirdelete   )protocolN)r   r   mkdirtempfileNamedTemporaryFiler$   parentr   dumposreplacenameOSError)r   r    r   r   Z	new_cachefr   r   r   write_cacheF   s   r<   )__doc__r7   r   pathlibr   r3   typingr   r   r   r   platformdirsr   Z
black.moder   Z_black_versionr	   __version__float	TimestampintZFileSize	CacheInfor$   Cacher   r   r   r   r)   r<   r   r   r   r   <module>   s&    *"