
    yIf                     @   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 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)err)      )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     ?/var/www/piapp/venv/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_filer0   2   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          |          }	 |                                }n8# t          $ r+}t          d| d|             | ||          cY d}~S d}~ww xY w|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.
        zUnable to read cache file z due to Nrbc                 (    i | ]\  }}|t          | S r   )r   .0kvs      r    
<dictcomp>zCache.read.<locals>.<dictcomp>P   s"    FFFAQ!FFFr   )r0   existsOSErrorr   openpickleloaditemsUnpicklingError
ValueError
IndexError)clsr,   r3   r>   efobjdatar5   s           r    readz
Cache.read<   s    $D))
	)&&((FF 	) 	) 	)DZDDDDEEE3tZ((((((((	)  	)3tZ(((__T"" 	-d-:@+d:K:KFFFFF		*J
C - - -s4,,,,	- 	- 	- 	- 	- 	- 	- 	-- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- s4Y///sP   & 
A AAAC=2B65C=6(C-C=,C--C==DDpathc                 v    |                                  }t          j        |                                          S )zReturn hash digest for path.)
read_byteshashlibsha256	hexdigest)rL   rJ   s     r    hash_digestzCache.hash_digestV   s/       ~d##--///r   c                     |                                  }t                              |           }t          |j        |j        |          S )zReturn file data for path.)statr2   rR   r   r   r   )rL   rT   r   s      r    get_file_datazCache.get_file_data]   s:     yy{{  &&t|T:::r   sourcec                 >   |                                 }| j                            t          |                    }|dS |                                }|j        |j        k    rdS |j        |j        k    r't                              |          }||j	        k    rdS dS )z7Check if source has changed compared to cached version.NTF)
resolver5   r'   r   rT   r   r   r2   rR   r   )selfrV   res_srcoldstnew_hashs         r    
is_changedzCache.is_changede   s    ..""n  W..;4\\^^:$$4;#,&&((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)rY   r_   changeddonesrcs        r    filtered_cachedzCache.filtered_cachedu   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   rX   r2   rU   )r:   re   s     r    r=   zCache.write.<locals>.<dictcomp>   s8    OOOs3;;==!!5#6#6s#;#;OOOr   T)parentsexist_okF)dirdeletec                      i | ]\  }}|g |R S r   r   r9   s      r    r=   zCache.write.<locals>.<dictcomp>   s1     ; ; ;!%AAuuu; ; ;r      )protocolNr   )r5   updater.   mkdirtempfileNamedTemporaryFiler   r3   parentrC   rA   dumpr%   replacenamer?   )rY   r_   frJ   s       r    writezCache.write   sS    	
 	
OOwOOO	
 	
 	
	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   dictr5   r   r   r   classmethodr   rK   staticmethodrR   rU   boolr^   r   r
   r	   rf   ry   r   r   r    r2   r2   6   sY        
JJJ%*U4%@%@%@ItCM"@@@0 0 0 0 0 [02 0$ 03 0 0 0 \0 ;D ;X ; ; ; \; $     x~ %D	3t9@T:U    Xd^       r   r2   )"__doc__rO   r%   rA   sysrr   dataclassesr   r   pathlibr   typingr   r   r   r	   r
   platformdirsr   _black_versionr   r(   
black.moder   black.outputr   version_infor   typing_extensionsr   r+   r.   r0   r2   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	> >$ > > > > _ _ _ _ _ _ _ _ _ _r   