
    5pj                        % S r SSKrSSKrSSKrSSKrSSKJr  SSKJr  SSK	J
r
  \R                  " \5      rSr0 r\\S4   \S'   \R&                  " 5       r\" S	S
9 " S S5      5       rS\\\4   S\4S jrS\S\S\4S jrS\S\4S jrS\S\S\\\4   S-  4S jrS\S\\\4   S-  4S jrS\S\S\\\4   SS4S jrg)a5  On-disk cache for repository tree listings.

A tree listing is the set of files (with their download metadata) contained in a repo at a given commit. Because a
commit hash is immutable, its tree listing never changes and can be cached forever without any invalidation logic.

The listing is stored as a human-readable JSON file under `<tree_cache_folder>/trees/<commit_hash>.json`. The
folder depends on the download target: the per-repo `storage_folder` for `cache_dir` downloads, or
`local_dir/.cache/huggingface/` for `local_dir` downloads (see `tree_cache_folder_for_local_dir`).

```json
{
  "format_version": 1,
  "files": {
    "config.json": {"size": 519, "blob_id": "<git sha1>"},
    "model.safetensors": {"size": 1234, "blob_id": "...", "lfs_sha256": "<sha256>", "lfs_size": 1234, "xet_hash": "..."}
  }
}
```
    N)	dataclass   )logging)is_valid_xet_hashzdict[str, TreeCacheEntry]_IN_MEMORY_TREE_CACHET)frozenc                       \ rS rSr% Sr\\S'   \\S'   Sr\S-  \S'   Sr	\S-  \S'   Sr
\S-  \S'   S	\4S
 jr\S\S	S 4S j5       rSrg)TreeCacheEntry5   z^Raw metadata of a single file in a cached tree listing, mirroring the `/tree` endpoint fields.sizeblob_idN
lfs_sha256lfs_sizexet_hashreturnc                     U R                   U R                  S.nU R                  b  U R                  US'   U R                  US'   U R                  b  U R                  US'   U$ )N)r   r   r   r   r   r   r   r   r   r   )selfinfos     W/var/www/html/pdf-tiff/venv/lib/python3.13/site-packages/huggingface_hub/_tree_cache.pyto_jsonTreeCacheEntry.to_json?   sW    "iiDLLA??&!%D#}}D==$#}}D    r   c           	      |    U " US   US   UR                  S5      UR                  S5      UR                  S5      S9$ )Nr   r   r   r   r   r   )get)clsr   s     r   	from_jsonTreeCacheEntry.from_jsonH   sA    fOxx-XXj)XXj)
 	
r    )__name__
__module____qualname____firstlineno____doc__int__annotations__strr   r   r   dictr   classmethodr   __static_attributes__r   r   r   r
   r
   5   sh    h
IL!Jd
!HcDjHcDj  
T 
&6 
 
r   r
   entriesr   c                 B    [        S U R                  5        5       5      $ )z<Return whether all Xet hashes in the tree listing are valid.c              3   t   #    U  H.  oR                   S L =(       d    [        UR                   5      v   M0     g 7f)N)r   r   ).0entrys     r   	<genexpr>(is_valid_tree_entries.<locals>.<genexpr>U   s+     iXhu~~%J):5>>)JJXhs   68)allvalues)r+   s    r   is_valid_tree_entriesr4   S   s    iX_XfXfXhiiir   tree_cache_foldercommit_hashc                 J    [         R                  R                  U SU S35      $ )Ntreesz.jsonospathjoin)r5   r6   s     r   _tree_cache_pathr=   X   s!    77<<)7{m54IJJr   	local_dirc                 D    [         R                  R                  U SS5      $ )zGFolder under which the `trees/` cache lives for a `local_dir` download.z.cachehuggingfacer9   )r>   s    r   tree_cache_folder_for_local_dirrA   \   s    77<<	8];;r   c                 P   [        X5      n[           U[        ;   a&  [        U   n[        U5      (       a  UOSsSSS5        $  SSS5        [	        U5      nUb  [        U5      (       d  g[           U[        U'   SSS5        U$ ! , (       d  f       NG= f! , (       d  f       U$ = f)zbReturn the cached tree listing for a commit hash, or `None` if not cached, invalid, or unreadable.N)r=   _IN_MEMORY_TREE_CACHE_LOCKr   r4   _read_tree_cache_from_disk)r5   r6   r;   cached_entriesr+   s        r   read_tree_cacherF   a   s    -;D	#((248N%:>%J%J>PT 
$	#( 
$ ).G3G<<	#&-d# 
$N 
$	# 
$	#Ns   'B1
B
B
B%r;   c                     [        U SS9 n[        R                  " U5      nS S S 5        WR                  S5      [        :w  a  g US   R                  5        VVs0 s H  u  p4U[        R                  U5      _M     snn$ ! , (       d  f       Nd= fs  snnf ! [         a     g [        [        [        [        4 a%  n[        R                  SU  SU 35         S nAg S nAff = f)Nutf-8encodingformat_versionfilesz#Ignoring corrupted tree cache file : )openjsonloadr   TREE_CACHE_FORMAT_VERSIONitemsr
   r   FileNotFoundErrorOSError
ValueErrorKeyError	TypeErrorloggerwarning)r;   fdata	file_pathr   es         r   rD   rD   p   s    $)Q99Q<D *88$%)BBQUV]Q^QdQdQfgQfoi	>33D99Qfgg *)
 h Z95 <TF"QCHIsE   
B B!B B "B=B 
BB 
C"$C"=CC"c                    [        U5      (       d  g[        X5      n[        [        U5       Vs0 s H  oDX$   R	                  5       _M     snS.n [
        R                  " [
        R                  R                  U5      SS9  [        R                  " [
        R                  R                  U5      SS9u  pg[
        R                  " USSS	9 n[        R                  " XXS
S9  SSS5        [
        R                  " Xs5        [$           ['        U5      [(        U'   SSS5        gs  snf ! , (       d  f       NK= f! [         a%  n	[         R#                  SU SU	 35         Sn	A	gSn	A	ff = f! , (       d  f       g= f)zTWrite a valid tree listing to the cache (ignoring invalid entries and any failures).N)rK   rL   T)exist_okz.tmp)dirsuffixwrH   rI   r   )indentz,Ignored error while writing tree cache file rM   )r4   r=   rQ   sortedr   r:   makedirsr;   dirnametempfilemkstempfdopenrO   dumpreplacerT   rX   rY   rC   r(   r   )
r5   r6   r+   r;   r\   r[   tmp_fdtmp_pathrZ   r]   s
             r   write_tree_cachern      s     ))-;D3KQRY?[?iW/7799?[D
BGGOOD)D9#++0EfUYYvsW5IIda( 6


8" 
$&*7md# 
$	# \
 65  EdV2aSQR
 
$	#sB   D#A<D9 D(#D9 E+(
D62D9 9
E(E##E(+
E9)r$   rO   r:   rg   	threadingdataclassesr   utilsr   
utils._xetr   
get_loggerr    rX   rQ   r   r(   r'   r&   LockrC   r
   boolr4   r=   rA   rF   rD   rn   r   r   r   <module>rv      sH  (  	   !  ) 
		H	%  AC tC!<<= B&^^-  $
 
 
:j4^(;#< j j
K K# K# K<s <s <
s  c>FYAZ]aAa S T#~2E-F-M 4 4# 4SR`M`Ha 4fj 4r   