
    Ng]
                     n    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dS )    N)CallableListOptional)requestT)filenameprogressurldirr   r   returnc                   t          j        |d           |G|                     d          d         }t          |          sJ d                    |                       t           j                            ||          }t          j        t                    }t           j        
                    |          r*|                    d                    |                     |S |dz   }	 |                    d	                    |                      |rd
dl}d|j        dt          t          t          t          t                   gdf         fd}|                    ddd|d          5 }	t!          j        | | ||	                    \  }}
ddd           n# 1 swxY w Y   nt!          j        | |          \  }}
t          j        |          }|j        }|d
k    r"t)          d                    |                     t+          j        ||           n7# t(          $ r* |                    d                    |                       w xY w	 	 t          j        |           n:# t(          $ r Y n.w xY w# 	 t          j        |           w # t(          $ r Y w w xY wxY w|                    d|z   dz   t3          |          z   dz              |S )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           	      d     dgddt           dt           dt          t                    dd f fd}|S )Nr   bbsizetsizer   c                 f    ||_                             | d         z
  |z             | d<   d S )Nr   )totalupdate)r   r   r   last_br   s      R/var/www/html/ai-engine/env/lib/python3.11/site-packages/iopath/common/download.pyinnerz%download.<locals>.hook.<locals>.inner/   s<    ("'HHa&)mu4555 !F1III    )N)intr   )r   r   r   s   ` @r   hookzdownload.<locals>.hook,   sZ    %&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   
   s5   " Kd####99S>>"%8}}NNBII#NNNNNGLLh''Ex((F	w~~e 8??IIJJJ
&.C%-44S99::: 	<KKK		 	hS(3-/H$/N&O 	 	 	 	 TAHD    T ,S344PQ77SSSQT T T T T T T T T T T T T T T (s;;;FC73<<199=DDSIIJJJ 	C   ,33C88999 	 
	IcNNNN 	 	 	D		IcNNNN 	 	 	D	 KK*U2T9CIIE	QRRRLsz   (A?H '$FH FH FA5H I3 4I		I3 I# #
I0/I03J5J
	J

JJJJ)r-   r&   r7   typingr   r   r   urllibr   r;   boolrB    r   r   <module>rG      s     				  + + + + + + + + + +       6:DE E E	EE%-c]EEIEE E E E E Er   