
    ɭde                     4   d 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mZ ddl	m
Z
 ddlmZmZmZmZmZ ddlmZ ddlmZ ddlmZ ej        d	k    rdd
lmZ ndd
lmZ  G d de          Zde
fdZ e            Zdede
fdZe G d d                      ZdS )z;Caching of formatted files with feature-based invalidation.    N)	dataclassfield)Path)DictIterable
NamedTupleSetTuple)user_cache_dir)version)Mode)      )Selfc                   .    e Zd ZU eed<   eed<   eed<   dS )FileDatast_mtimest_sizehashN)__name__
__module____qualname__float__annotations__intstr     +lib/python3.11/site-packages/black/cache.pyr   r      s+         OOOLLL
IIIIIr   r   returnc                      t          d          } t          t          j                            d|                     }|t
          z  }|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.
    blackBLACK_CACHE_DIR)r   r   osenvironget__version__)default_cache_dir	cache_dirs     r   get_cache_dirr*      sA     'w//RZ^^$57HIIJJIK'Ir   modec                 B    t           d|                                  dz  S )Nzcache.z.pickle)	CACHE_DIRget_cache_key)r+   s    r   get_cache_filer/   1   s%    = 2 2 4 4=====r   c                   &   e Zd ZU eed<   eed<    ee          Ze	e
ef         ed<   ededefd            Zedede
fd            Zededefd	            Zd
edefdZdee         deee         ee         f         fdZdee         ddfdZdS )Cacher+   
cache_file)default_factory	file_datar    c                    t          |          }|                                s | ||          S |                    d          5 }	 t          j        |          }d |                                D             }n:# t          j        t          t          f$ r  | ||          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 later should
        resolve the issue.
        rbc                 (    i | ]\  }}|t          | S r   )r   .0kvs      r   
<dictcomp>zCache.read.<locals>.<dictcomp>I   s"    FFFAQ!FFFr   N)	r/   existsopenpickleloaditemsUnpicklingError
ValueError
IndexError)clsr+   r2   fobjdatar4   s         r   readz
Cache.read;   sI    $D))
  "" 	)3tZ(((__T"" 	-d-:@+d:K:KFFFFF		*J
C - - -s4,,,,	- 	- 	- 	- 	- 	- 	- 	-- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- s4Y///s6   C2A:9C:(B1"C0B11CCCpathc                 v    |                                  }t          j        |                                          S )zReturn hash digest for path.)
read_byteshashlibsha256	hexdigest)rI   rG   s     r   hash_digestzCache.hash_digestO   s/       ~d##--///r   c                     |                                  }t                              |           }t          |j        |j        |          S )zReturn file data for path.)statr1   rO   r   r   r   )rI   rQ   r   s      r   get_file_datazCache.get_file_dataV   s:     yy{{  &&t|T:::r   sourcec                 r   |                                 }| j                            t          |                    }|dS |                                }|j        |j        k    rdS t          |j                  t          |j                  k    r't          	                    |          }||j
        k    rdS dS )z7Check if source has changed compared to cached version.NTF)resolver4   r&   r   rQ   r   r   r   r1   rO   r   )selfrS   res_srcoldstnew_hashs         r   
is_changedzCache.is_changed^   s    ..""n  W..;4\\^^:$$4r{s3<0000((11H38##tur   sourcesc                     t                      }t                      }|D ]B}|                     |          r|                    |           -|                    |           C||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.
        )setr[   add)rV   r\   changeddonesrcs        r   filtered_cachedzCache.filtered_cachedn   si     !UU%% 	 	Cs## C    }r   Nc                     | j         j        d
i d |D              	 t                              dd           t	          j        t          | j        j                  d          5 }d | j         	                                D             }t          j        ||d           d	d	d	           n# 1 swxY w Y   t          j        |j        | j                   d	S # t          $ r Y d	S w xY w)z6Update the cache file data and write a new cache file.c                     i | ]<}t          |                                          t                              |          =S r   )r   rU   r1   rR   )r9   rb   s     r   r<   zCache.write.<locals>.<dictcomp>   sE     !
 !
 !
=@C 3 3C 8 8!
 !
 !
r   T)parentsexist_okF)dirdeletec                      i | ]\  }}|g |R S r   r   r8   s      r   r<   zCache.write.<locals>.<dictcomp>   s1     ; ; ;!%AAuuu; ; ;r      )protocolNr   )r4   updater-   mkdirtempfileNamedTemporaryFiler   r2   parentrA   r?   dumpr$   replacenameOSError)rV   r\   frG   s       r   writezCache.write}   s^    	 	 !
 !
DK!
 !
 !
 	 	 		OOD4O888,.//   1; ;)-)=)=)?)?; ; ; D!a00001 1 1 1 1 1 1 1 1 1 1 1 1 1 1 Jqvt///// 	 	 	DD	s6   A	C ';B."C .B22C 5B26"C 
C('C()r   r   r   r   r   r   r   dictr4   r   r   r   classmethodr   rH   staticmethodrO   rR   boolr[   r   r
   r	   rc   rw   r   r   r   r1   r1   5   sY        
JJJ%*U4%@%@%@ItCM"@@@0 0 0 0 0 [0& 0$ 03 0 0 0 \0 ;D ;X ; ; ; \; $     x~ %D	3t9@T:U    Xd^       r   r1   ) __doc__rL   r$   r?   sysro   dataclassesr   r   pathlibr   typingr   r   r   r	   r
   platformdirsr   _black_versionr   r'   
black.moder   version_infor   typing_extensionsr   r*   r-   r/   r1   r   r   r   <module>r      s   A A  				  



  ( ( ( ( ( ( ( (       9 9 9 9 9 9 9 9 9 9 9 9 9 9 ' ' ' ' ' ' 1 1 1 1 1 1      w&&&&&&    z   t    " MOO	> >$ > > > > Y Y Y Y Y Y Y Y Y Yr   