
    kh]
                     f    d dl Z d dlZd dlZd dlmZmZmZ d dlmZ dddde	de	dee	   d	e
d
e	f
dZy)    N)CallableListOptional)requestT)filenameprogressurldirr   r   returnc                   t        j                  |d       |5| j                  d      d   }t        |      sJ dj	                  |              t         j
                  j                  ||      }t        j                  t              }t         j
                  j                  |      r"|j                  dj	                  |             |S |dz   }	 |j                  d	j	                  |              |rvd
dl}d|j                  dt        t        t        t        t           gdf   fd}|j                  ddd|d      5 }	t!        j"                  | | ||	            \  }}
ddd       nt!        j"                  | |      \  }}
t        j$                  |      }|j&                  }|d
k(  rt)        dj	                  |             t+        j,                  ||       	 	 t        j0                  |       |j                  d|z   dz   t3        |      z   dz          |S # 1 sw Y   xY w# t(        $ r" |j/                  dj	                  |               w xY w# t(        $ r Y mw xY w# 	 t        j0                  |       w # t(        $ r Y w w xY wxY w)a  
    Download a file from a given URL to a directory. If file exists, will not
        overwrite the existing file.

    Args:
        url (str):
        dir (str): the directory to download the file
        filename (str or None): the basename to save the file.
            Will use the name in the URL if not given.
        progress (bool): whether to use tqdm to draw a progress bar.

    Returns:
        str: the path to the downloaded file or the existing one.
    T)exist_okN/z"Cannot obtain filename from url {}z"File {} exists! Skipping download.z.tmpzDownloading from {} ...r   tr   c           	      V     dgddt         dt         dt        t            dd f fd}|S )Nr   bbsizetsizer   c                 V    ||_         j                  | d   z
  |z         | d<   y )Nr   )totalupdate)r   r   r   last_br   s      R/var/www/teggl/fontify/venv/lib/python3.12/site-packages/iopath/common/download.pyinnerz%download.<locals>.hook.<locals>.inner/   s2    ("'HHa&)mu45 !F1I    )N)intr   )r   r   r   s   ` @r   hookzdownload.<locals>.hook,   s6    %&C"S " "Xc] "d " r   B   )unit
unit_scaleminitersdescleave)r   
reporthook)r   z!Downloaded an empty file from {}!zFailed to download {}zSuccessfully downloaded z. z bytes.)osmakedirssplitlenformatpathjoinlogging	getLogger__name__isfileinfotqdmr   r   r   r   urlretrievestatst_sizeIOErrorshutilmoveerrorunlinkstr)r	   r
   r   r   fpathloggertmpr2   r   r   _statinfosizes                r   downloadrB   
   sG   " KKd#99S>"%8}NBII#NN}GGLLh'Ex(F	ww~~e8??IJ
&.C%-44S9:			 	hS(3-/H$/N&O 	 TAHD   T ,,S34PQ7SQT T ((s;FC773<19=DDSIJJ 	C
	IIcN KK*U2T9CIE	QRL1T T  ,33C89  			IIcN 		sh   A-H" <"HA9H" I HH" "+II 	IIJ!I76J7	J JJJ)r-   r&   r7   typingr   r   r   urllibr   r;   boolrB    r   r   <module>rG      sW     	  + +  6:DE	EE%-c]EEIEEr   