
    !.d              	       V   d 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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defd	Z e            Zd
edefdZd
edefdZdedefdZdedee         de
e	e         e	e         f         fdZdedee         d
eddfdZdS )z;Caching of formatted files with feature-based invalidation.    N)Path)DictIterableSetTuple)user_cache_dirversion)Modereturnc                      t          dt                    } t          t          j                            d|                     }|S )a[  Get the cache directory used by black.

    Users can customize this directory on all systems using `BLACK_CACHE_DIR`
    environment variable. By default, the cache directory is the user cache directory
    under the black application.

    This result is immediately set to a constant `black.cache.CACHE_DIR` as to avoid
    repeated calls.
    blackr	   BLACK_CACHE_DIR)r   __version__r   osenvironget)default_cache_dir	cache_dirs     +lib/python3.11/site-packages/black/cache.pyget_cache_dirr      s<     'wDDDRZ^^$57HIIJJI    modec                 8   t          |           }|                                si S |                    d          5 }	 t          j        |          }n0# t          j        t          t          f$ r i cY cddd           S w xY w	 ddd           n# 1 swxY w 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
IndexError)r   
cache_filefobjcaches       r   
read_cacher'   (   s   
  %%J 				 $	!;t,,EE&
J? 	 	 	II	       	                Ls4   BABA?0B>A??BBBc                 B    t           d|                                  dz  S )Nzcache.z.pickle)	CACHE_DIRget_cache_key)r   s    r   r   r   :   s%    = 2 2 4 4=====r   pathc                 F    |                                  }|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-   s     r   get_cache_infor0   >   s    99;;D=$,&&r   r&   sourcesc                 0   t                      t                      }}|D ]t}|                                }|                     t          |                    t	          |          k    r|                    |           _|                    |           u||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resolver   strr0   add)r&   r1   tododonesrcres_srcs         r   filter_cachedr;   D   s     $D  ++--99S\\""nW&=&===HHSMMMMHHSMMMM:r   c                    t          |          }	 t                              dd           i | d |D             }t          j        t          |j                  d          5 }t          j        ||d           ddd           n# 1 swxY w Y   t          j
        |j        |           dS # t          $ r Y dS w xY w)	zUpdate the cache file.T)parentsexist_okc                 l    i | ]1}t          |                                          t          |          2S  )r5   r4   r0   ).0r9   s     r   
<dictcomp>zwrite_cache.<locals>.<dictcomp>[   s2    JJJ3s3;;==!!>##6#6JJJr   F)dirdelete   )protocolN)r   r)   mkdirtempfileNamedTemporaryFiler5   parentr   dumpr   replacenameOSError)r&   r1   r   r$   	new_cachefs         r   write_cacherQ   T   s   %%J
t444

JJ'JJJ
	 (S1B-C-CERRR 	2VWK	1q1111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2

16:&&&&&   s6   AB0 %B	=B0 	BB0 BB0 0
B>=B>) __doc__r   r   rH   pathlibr   typingr   r   r   r   platformdirsr   _black_versionr
   r   
black.moder   float	TimestampintFileSize	CacheInfor5   Cacher   r)   r'   r   r0   r;   rQ   r@   r   r   <module>r^      s   A A 				         - - - - - - - - - - - - ' ' ' ' ' ' 1 1 1 1 1 1       	)X%&	S)^t      MOO	T e    $> >$ > > > >' ') ' ' ' ' $ E#d)SQUYBV<W     u x~ T d      r   