
    h                     *   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 ddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ej0                  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y)z;Caching of formatted files with feature-based invalidation.    N)Iterable)	dataclassfield)Path)
NamedTuple)user_cache_dir)version)Mode)err)      )Selfc                   ,    e Zd ZU eed<   eed<   eed<   y)FileDatast_mtimest_sizehashN)__name__
__module____qualname__float__annotations__intstr     >/var/www/html/immo/lib/python3.12/site-packages/black/cache.pyr   r      s    OL
Ir   r   returnc                      t        d      } t        t        j                  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(      s:     'w/RZZ^^$57HIJIK'Ir   modec                 8    t         d| j                          dz  S )Nzcache.z.pickle)	CACHE_DIRget_cache_key)r)   s    r   get_cache_filer-   3   s      2 2 45W===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y)Cacher)   
cache_file)default_factory	file_datar   c           	         t        |      }	 |j                         }|s	 | ||      S |j	                  d      5 }	 t        j                  |      }|j                         D ci c]  \  }}|t        |  }	}}	 ddd        | ||	      S # t        $ r$}t        d| d|         | ||      cY d}~S d}~ww xY wc c}}w # t
        j                  t        t        f$ r  | ||      cY cddd       S w xY w# 1 sw Y   xY w)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rb)r-   existsOSErrorr   openpickleloaditemsr   UnpicklingError
ValueError
IndexError)
clsr)   r0   r5   efobjdatakvr2   s
             r   readz
Cache.read=   s    $D)
	)&&(F
 tZ((__T" 	-d-:@++d:K9=FAQ!_F	F	- 4Y//  	),ZLDEtZ((	) G**J
C -4,,	- 	--		- 	-sW   B C8(C#B<6C	B9B4.B94B9<C'C5)C84C55C88Dpathc                 h    | j                         }t        j                  |      j                         S )zReturn hash digest for path.)
read_byteshashlibsha256	hexdigest)rE   rA   s     r   hash_digestzCache.hash_digestW   s(      ~~d#--//r   c                     | j                         }t        j                  |       }t        |j                  |j
                  |      S )zReturn file data for path.)statr/   rK   r   r   r   )rE   rM   r   s      r   get_file_datazCache.get_file_data^   s6     yy{  &t||T::r   sourcec                 B   |j                         }| j                  j                  t        |            }|y|j	                         }|j
                  |j
                  k7  ry|j                  |j                  k7  r%t        j                  |      }||j                  k7  ryy)z7Check if source has changed compared to cached version.TF)
resolver2   r$   r   rM   r   r   r/   rK   r   )selfrO   res_srcoldstnew_hashs         r   
is_changedzCache.is_changedf   s~    .."nn  W.;\\^::$;;#,,&((1H388#r   sourcesc                     t               }t               }|D ]6  }| j                  |      r|j                  |       &|j                  |       8 ||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.
        )setrW   add)rR   rX   changeddonesrcs        r   filtered_cachedzCache.filtered_cachedv   sP     !U% 	Cs#C 		
 }r   Nc                     | j                   j                  di |D ci c]/  }t        |j                               t        j                  |      1 c} 	 t        j                  dd       t        j                  t        | j                  j                        d      5 }| j                   j                         D ci c]  \  }}|g | }}}t        j                  ||d       ddd       t        j                   j"                  | j                         yc c}w c c}}w # 1 sw Y   ?xY w# t$        $ r Y yw xY w)	z6Update the cache file data and write a new cache file.T)parentsexist_okF)dirdelete   )protocolNr   )r2   updater   rQ   r/   rN   r+   mkdirtempfileNamedTemporaryFiler0   parentr:   r8   dumpr"   replacenamer6   )rR   rX   r^   frB   rC   rA   s          r   writezCache.write   s    	
GNOs3;;=!5#6#6s#;;O	
	OOD4O8,,../ 1 *.)=)=)?;!%AAuuH; ; D!a01 JJqvvt/ P;	1 1  		sB   4DAD5 "D) D#D)+2D5 #D))D2.D5 5	E E)r   r   r   r
   r   r   r   dictr2   r   r   classmethodr   rD   staticmethodrK   rN   boolrW   r   tuplerZ   r_   rp   r   r   r   r/   r/   7   s    
J%*4%@ItCM"@0 0 0 02 0$ 03 0 0 ;D ;X ; ; $  x~ %D	3t9@T:U Xd^  r   r/   ) __doc__rH   r"   r8   sysri   collections.abcr   dataclassesr   r   pathlibr   typingr   platformdirsr   _black_versionr	   r%   
black.moder
   black.outputr   version_infor   typing_extensionsr   r(   r+   r-   r/   r   r   r   <module>r      s    A  	  
  $ (   ' 1  w&z t " O	> >$ > ^ ^ ^r   