
    h                      <    S r SSKrSSKrSSKrSSKJr  S rSS jrg)zi
This code file mainly comes from https://github.com/dmlc/gluon-cv/blob/master/gluoncv/utils/download.py
    N)tqdmc                 `   [         R                  " 5       n[        U S5       n UR                  S5      nU(       d  OUR	                  U5        M,  SSS5        UR                  5       n[        [        U5      [        U5      5      nUR                  5       SU USU :H  $ ! , (       d  f       NU= f)a  Check whether the sha1 hash of the file content matches the expected hash.
Parameters
----------
filename : str
    Path to the file.
sha1_hash : str
    Expected sha1 hash in hexadecimal digits.
Returns
-------
bool
    Whether the file content matches the expected hash.
rbi   Nr   )hashlibsha1openreadupdate	hexdigestminlen)filename	sha1_hashr   fdata	sha1_filels          T/var/www/fran/franai/venv/lib/python3.13/site-packages/insightface/utils/download.py
check_sha1r   
   s     <<>D	h	66'?DKK	  
  IC	NC	N+A>>Aa IaN22 
	s   .B
B-c           	      D   Uc  U R                  S5      S   nOw[        R                  R                  U5      n[        R                  R	                  U5      (       a2  [        R                  R                  XR                  S5      S   5      nOUnU(       d=  [        R                  R                  U5      (       a  U(       Ga  [        XC5      (       Gd  [        R                  R                  [        R                  R                  [        R                  R                  U5      5      5      n[        R                  R                  U5      (       d  [        R                  " U5        [        SU< SU < S35        [        R                  " U SS9nUR                  S	:w  a  [        S
U -  5      eUR                   R                  S5      n[#        US5       nUc1  UR%                  SS9 H  n	U	(       d  M  UR'                  U	5        M     OL[)        U5      n[+        UR%                  SS9[)        US-  S-   5      SSSS9 H  n	UR'                  U	5        M     SSS5        U(       a*  [        XC5      (       d  [-        SR/                  U5      5      eU$ ! , (       d  f       NA= f)a  Download an given URL
Parameters
----------
url : str
    URL to download
path : str, optional
    Destination path to store downloaded file. By default stores to the
    current directory with same name as in url.
overwrite : bool, optional
    Whether to overwrite destination file if already exists.
sha1_hash : str, optional
    Expected sha1 hash in hexadecimal digits. Will ignore existing file when hash is specified
    but doesn't match.
Returns
-------
str
    The file path of the downloaded file.
N/zDownloading z from z...T)stream   zFailed downloading url %szcontent-lengthwbi   )
chunk_sizeg      @g      ?KBF)totalunit
unit_scaledynamic_ncolszFile {} is downloaded but the content hash does not match. The repo may be outdated or download may be incomplete. If the "repo_url" is overridden, consider switching to the default repo.)splitospath
expanduserisdirjoinexistsr   dirnameabspathmakedirsprintrequestsgetstatus_codeRuntimeErrorheadersr   iter_contentwriteintr   UserWarningformat)
urlr$   	overwriter   fnamer)   rtotal_lengthr   chunks
             r   download_filer=   $   s   & |		#r"ww!!$'77==GGLLyy~b'9:EEu--j::''//"''//"''2D2DU2K"LMww~~g&&KK UC89LLT*==C:S@AAyy}}%56%!#^^t^<Eu =  #<0!!..D."A(+L5,@3,F(G'+-204	6E
 GGEN6  Z99 2 39&-A A
 L) s   J4A"J
J)NFN)__doc__r#   r   r-   r   r   r=        r   <module>rA      s"    
   34;r@   