
    -ix                        d dl Z d dl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mZ erdd
lmZmZ  e j        d          Z G d de	          Zed         Z ed           G d d                      Zdedeeef         fdZdedee         defdZdededefdZdeee
d
         f         deeef         dededef
dZd ed!edee         d"ee         d#ee         de eef         fd$Z!dS )%    N)	dataclass)Path)TYPE_CHECKINGLiteralOptional	TypedDictUnion   )	constants)repo_folder_name   )git_hashsha_fileobj)RepoFile
RepoFolderz^[0-9a-f]{40}$c                   8    e Zd ZU eed<   eed<   eed<   eed<   dS )Mismatchpathexpectedactual	algorithmN)__name__
__module____qualname__str__annotations__     a/var/www/html/speakWrite/venv/lib/python3.11/site-packages/huggingface_hub/utils/_verification.pyr   r      s4         
IIIMMMKKKNNNNNr   r   )sha256git-sha1T)frozenc                   p    e Zd ZU eed<   eed<   ee         ed<   ee         ed<   ee         ed<   eed<   dS )FolderVerificationrevisionchecked_count
mismatchesmissing_pathsextra_pathsverified_pathN)	r   r   r   r   r   intlistr   r   r   r   r   r$   r$      sc         MMMX9cr   r$   rootreturnc                 F      fd                      d          D             S )z]
    Return a mapping of repo-relative path -> absolute path for all files under `root`.
    c                     i | ]>}|                                 |                                                              |?S r   )is_filerelative_toas_posix).0pr-   s     r   
<dictcomp>z'collect_local_files.<locals>.<dictcomp>+   s@    VVV!!))++VAMM$((**AVVVr   *)rglob)r-   s   `r   collect_local_filesr9   '   s*     WVVVtzz#VVVVr   storage_folderr%   c                 d   |rt                               |          r|S | dz  }| dz  }|rW||z  }|                                r(|                    d                                          S t          d| d| d          |dz  }|                                r(|                    d                                          S |                                st          d	| d
          d |                                D             }t          |          dk    r|d         S t          d          )zR
    Resolve a commit hash from a cache repo folder and an optional revision.
    refs	snapshotszutf-8)encodingz
Revision 'z1' could not be resolved in cache (expected file 'z').mainz+Cache repo is missing snapshots directory: z . Provide --revision explicitly.c                     g | ]<}|                                 t                              |j                  5|j        =S r   )is_dir_REGEX_COMMIT_HASH	fullmatchname)r4   r5   s     r   
<listcomp>z3_resolve_commit_hash_from_cache.<locals>.<listcomp>F   s?    qqqQQXXZZqL^LhLhijioLpLpq!&qqqr   r   r   zhAmbiguous cached revision: multiple snapshots found and no refs to disambiguate. Please pass --revision.)	rB   rC   r1   	read_textstrip
ValueErrorrA   iterdirlen)r:   r%   refs_dirsnapshots_dirref_pathmain_ref
candidatess          r   _resolve_commit_hash_from_cacherP   .   sj     &00:: &H"[0M ph& 	@%%w%77==???nhnnainnnooo & H <!!7!3399;;;!! xv}vvvwwwqq-"7"7"9"9qqqJ
:!!}
r  r   r   r   c                 8   |                      d          5 }|dk    r-t          |                                          cddd           S |dk    r-t          |                                          cddd           S t          d|           # 1 swxY w Y   dS )zM
    Compute the checksum of a local file using the requested algorithm.
    rbr    Nr!   zUnsupported hash algorithm: )openr   hexr   readrH   )r   r   streams      r   compute_file_hashrW   O   s   
 
4 EF  v&&**,,E E E E E E E E 
""FKKMM**	E E E E E E E E
 C	CCDDDE E E E E E E E E Es   'B
&B=BBBremote_by_pathlocal_by_pathr*   c           	         t          |           }t          |          }t          ||z
            }t          ||z
            }t          ||z            }g }	|D ]}
| |
         }||
         }t          |dd          }|t          |dd          nd}|*t          |t                    r|                    d          }|r$d}t          |                                          }n*|j        }d}t          |                                          }t          ||          }||k    r&|	
                    t          |
|||                     t          |t          |          |	|||          S )zHCompare remote entries and local files and return a verification result.lfsNr    r!   )r   r   r   r   )r%   r&   r'   r(   r)   r*   )setsortedgetattr
isinstancedictgetr   lowerblob_idrW   appendr   r$   rJ   )rX   rY   r%   r*   remote_pathslocal_pathsmissingextrabothr'   rel_pathremote_entry
local_pathr[   lfs_shar   r   rc   r   s                      r   verify_mapsrn   \   s    ~&&Lm$$K\K/00G;-..E,,--D!#J n n%h/"8,
lE40025/'#x...t?z#t44?ggh''G 	,"*I7||))++HH"*G"I7||))++H":y99XhHxPVbklllmmm$ii#   r   repo_id	repo_type	cache_dir	local_dirc                 X   |it          |                                                                          }|                                st	          d|           ||pt
          j        fS t          |pt
          j                                                                                  }|t          | |          z  }|	                                st	          d| d          t          ||          }|dz  |z  }	|	                                st	          d| d|	 d	          |	|fS )
zW
    Resolve the root directory to scan locally and the remote revision to verify.
    Nz6Local directory does not exist or is not a directory: )ro   rp   zRepo is not present in cache: z.. Use 'hf download' first or pass --local-dir.r=   z0Snapshot directory does not exist for revision 'z': .)r   
expanduserresolverA   rH   r   DEFAULT_REVISIONHF_HUB_CACHEr   existsrP   )
ro   rp   r%   rq   rr   r-   
cache_rootr:   commitsnapshot_dirs
             r   resolve_local_rootr}      sE    I))++3355{{}} 	^\VZ\\]]]h<)"<==i99#9::EEGGOOQQJ"27i"X"X"XXN  "" 
k^kkk
 
 	
 -^XFFF!K/&8L   hfFffWcfffgggr   )"redataclassesr   pathlibr   typingr   r   r   r   r	    r   file_downloadr   shar   r   hf_apir   r   compilerB   r   HashAlgor$   r`   r   r9   rP   rW   rn   tupler}   r   r   r   <module>r      s   				 ! ! ! ! ! !       E E E E E E E E E E E E E E       , , , , , , & & & & & & & &  .--------  RZ 122     y    '( $       Wd WtCI W W W WD HSM VY    B
ED 
EX 
E# 
E 
E 
E 
E-e$<==>- T	?- 	-
 - - - - -`     sm	 
 ~  ~  49           r   