
    _ix                        S SK r S SKJr  S SKJr  S SKJrJrJrJ	r	J
r
  SSKJr  SSKJr  SS	KJrJr  \(       a  SS
KJrJr  \ R*                  " S5      r " S S\	5      r\S   r\" SS9 " S S5      5       rS\S\\\4   4S jrS\S\\   S\4S jrS\S\S\4S jrS\\\
S
   4   S\\\4   S\S\S\4
S jrS \S!\S\\   S"\\   S#\\   S\ \\4   4S$ jr!g)%    N)	dataclass)Path)TYPE_CHECKINGLiteralOptional	TypedDictUnion   )	constants)repo_folder_name   )git_hashsha_fileobj)RepoFile
RepoFolderz^[0-9a-f]{40}$c                   >    \ rS rSr% \\S'   \\S'   \\S'   \\S'   Srg)Mismatch   pathexpectedactual	algorithm N)__name__
__module____qualname____firstlineno__str__annotations____static_attributes__r       _/var/www/html/land-ocr/venv/lib/python3.13/site-packages/huggingface_hub/utils/_verification.pyr   r      s    
IMKNr!   r   )sha256git-sha1T)frozenc                   d    \ rS rSr% \\S'   \\S'   \\   \S'   \\   \S'   \\   \S'   \	\S'   Sr
g	)
FolderVerification   revisionchecked_count
mismatchesmissing_pathsextra_pathsverified_pathr   N)r   r   r   r   r   r   intlistr   r   r    r   r!   r"   r'   r'      s1    MX9cr!   r'   rootreturnc                     U R                  S5       Vs0 s H9  oR                  5       (       d  M  UR                  U 5      R                  5       U_M;     sn$ s  snf )zU
Return a mapping of repo-relative path -> absolute path for all files under `root`.
*)rglobis_filerelative_toas_posix)r1   ps     r"   collect_local_filesr:   '   sD     8<zz#V!))+-AMM$((*A-VVVs
   A$Astorage_folderr)   c                    U(       a  [         R                  U5      (       a  U$ U S-  nU S-  nU(       aH  X!-  nUR                  5       (       a  UR                  SS9R	                  5       $ [        SU SU S35      eUS-  nUR                  5       (       a  UR                  SS9R	                  5       $ UR                  5       (       d  [        S	U S
35      eUR                  5        Vs/ s HK  ofR                  5       (       d  M  [         R                  UR                  5      (       d  M?  UR                  PMM     nn[        U5      S:X  a  US   $ [        S5      es  snf )zJ
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.r   r   zhAmbiguous cached revision: multiple snapshots found and no refs to disambiguate. Please pass --revision.)
_REGEX_COMMIT_HASH	fullmatchr6   	read_textstrip
ValueErroris_diriterdirnamelen)r;   r)   refs_dirsnapshots_dirref_pathmain_refr9   
candidatess           r"   _resolve_commit_hash_from_cacherO   .   sQ    &00::&H"[0M&%%w%7==??:hZ/`ai`jjmnoo & H!!7!399;;!!F}oUuvww"/"7"7"9q"9QXXZ&L^LhLhijioioLp&!&&"9Jq
:!!}
r 	 rs   *E"E,Er   r   c                    U R                  S5       nUS:X  a"  [        U5      R                  5       sSSS5        $ US:X  a"  [        UR	                  5       5      sSSS5        $ [        SU 35      e! , (       d  f       g= f)zE
Compute the checksum of a local file using the requested algorithm.
rbr#   Nr$   zUnsupported hash algorithm: )openr   hexr   readrE   )r   r   streams      r"   compute_file_hashrV   O   sm    
 
4F v&**, 
 
"FKKM*	 

 7	{CDD 
s   A1A1#A11
A?remote_by_pathlocal_by_pathr.   c           
      P   [        U 5      n[        U5      n[        XE-
  5      n[        XT-
  5      n[        XE-  5      n/ n	U H  n
X
   nX   n[        USS5      nUb  [        USS5      OSnUc&  [        U[        5      (       a  UR                  S5      nU(       a  Sn[        U5      R                  5       nO'UR                  nSn[        U5      R                  5       n[        X5      nUU:w  d  M  U	R                  [        U
UUUS95        M     [        U[        U5      U	UUUS9$ )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_idrV   appendr   r'   rI   )rW   rX   r)   r.   remote_pathslocal_pathsmissingextrabothr+   rel_pathremote_entry
local_pathrZ   lfs_shar   r   rb   r   s                      r"   verify_mapsrm   \   s-    ~&Lm$K\/0G;-.E,,-D!#J%/",
lE4025/'#x.t?z#t44ggh'G"*I7|))+H"**G"I7|))+H":9XhHxPVbklm' * $i# r!   repo_id	repo_type	cache_dir	local_dirc                 &   Ubd  [        U5      R                  5       R                  5       nUR                  5       (       d  [	        SU 35      eXR=(       d    [
        R                  4$ [        U=(       d    [
        R                  5      R                  5       R                  5       nU[        XS9-  nUR                  5       (       d  [	        SU S35      e[        Xr5      nUS-  U-  n	U	R                  5       (       d  [	        SU SU	 S35      eX4$ )	zO
Resolve the root directory to scan locally and the remote revision to verify.
z6Local directory does not exist or is not a directory: )rn   ro   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resolverF   rE   r   DEFAULT_REVISIONHF_HUB_CACHEr   existsrO   )
rn   ro   r)   rp   rq   r1   
cache_rootr;   commitsnapshot_dirs
             r"   resolve_local_rootr|      s    I))+335{{}}UVZU[\]]<)"<"<==i99#9#9:EEGOOQJ"27"XXN  "",^,<<jk
 	
 -^FF!K/&8L  KF8SVWcVddefggr!   )"redataclassesr   pathlibr   typingr   r   r   r   r	    r   file_downloadr   shar   r   hf_apir   r   compilerA   r   HashAlgor'   r_   r   r:   rO   rV   rm   tupler|   r   r!   r"   <module>r      sl   	 !  E E  , & - ZZ 12 y  '( $  Wd WtCI WD HSM VY B
ED 
EX 
E# 
E-e$<==>- T	?- 	-
 - -`     sm	 
 ~  ~  49 r!   