
    c                         d dl mZmZ d dlmZ d dlmZ d dlmZ d dlmc m	Z	 d dl
mc mZ d dlZd dlZ G d de          ZdS )    )absolute_importprint_function)
httpclient)gen)tqdmNc                   b    e Zd ZddZej        d             Zed             Zed             Z	dS )FileDownloaderNc                 h    || _         || _        || _        d| _        d| _        g | _        d| _        dS )zDownloader for the given url to the given filename, computing the given hash.

        hash_algorithm is the name of a hash function in hashlib
        N)_url	_filename_hash_algorithm_hash_client_errors	_progress)selfurlfilenamehash_algorithms       Elib/python3.11/site-packages/anaconda_project/internal/http_client.py__init__zFileDownloader.__init__   s:    
 	!-
    c              #   B   	
K    j         J t          j                             j                  }	 t          j        |           nF# t          $ r9} j        	                    d|d|           t          j        d          d}~ww xY w j        " t          t           j                              
t          j        dddd           _          j        d	z   	 t#          d
          	nF# t$          $ r9} j        	                    dd|           t          j        d          d}~ww xY w	fd}	
 fd} fd}	 d}t          j         j        |||          }	  j                             |          V }nX# t          $ rK} j        	                    d j        dt-          |                     t          j        d          d}~ww xY w	  j         j                                         n&#  j         j                                         w w xY w|j        J t5           j                  dk    r|	 	                                 t7          j         j                   nL# t$          $ r?} j        	                    dd j        dt-          |                     Y d}~nd}~ww xY wt5           j                  dk    r  j        
                                 _        t          j        |          #  |             w xY w)z&Run the download on the given io_loop.NzCould not create directory 'z':    i   l       d T)max_clientsmax_buffer_sizemax_body_sizeforce_instancez.partwbzFailed to open : c                  |    	                                    t          j                   d S # t          $ r Y d S w xY wN)closeosremoveEnvironmentError)_filetmp_filenames   r   cleanup_tmpz'FileDownloader.run.<locals>.cleanup_tmpD   sO    
 	,'''''#   s   (- 
;;c                 |   t          j                  dk    rd S j                            |            	                     |            j        /j                            t          |           dz  dz             d S d S # t          $ r+}j                            dd|           Y d }~d S d }~ww xY w)Nr      zFailed to write to r    )lenr   r   updatewriter   r&   append)chunker'   hasherr   r(   s     r   writerz"FileDownloader.run.<locals>.writerO   s    4<  1$ # %e$$$UE"""> DN))#e**t*;d*BCCCCCD D# U U U ###<<<QRQR$STTTTTTTTT	Us   A	B 
B; B66B;c                    d|                                  v rjt          |                     d          d                   dz  dz  }t          d|dt          j                            j                            _        d S d S )Nzcontent-length:r   r+   MiBT)unittotal
unit_scaledesc)	lowerintsplitr   r$   pathbasenamer   r   )line	file_sizer   s     r   read_headerz'FileDownloader.run.<locals>.read_header`   s    4::<</ M

3 233d:TA	!%5,515+-7+;+;DN+K+K"M "M "MM Mr   iX  )r   header_callbackstreaming_callbackrequest_timeoutzFailed download to r   zFailed to rename z to )r   r$   r>   dirnamer   makedirsmakedirs_ok_if_exists	Exceptionr   r/   r   Returnr   getattrhashlibr   AsyncHTTPClientopenr&   HTTPRequestr   fetchstrr   r#   errorr,   renamerename_over_existing	hexdigestr   )r   rF   r1   r)   r3   rB   timeout_in_secondsrequestresponser'   r2   r(   s   `        @@@r   runzFileDownloader.run#   s      |###'//$.11	#*73333 	# 	# 	#LRSRS TUUU*T"""	#  	>;WWd&:;;==F!1  (2
! 
! 
! ~/	#t,,EE 	# 	# 	#L<<< KLLL*T"""	#		 		 		 		 		 			U 	U 	U 	U 	U 	U 	U 	U"	M 	M 	M 	M 	M	!( ,=H@F=OQ Q QG+!%!3!3G!<!<<< ' ' '###4>>>SVWXSYSYSY$Z[[[j&&&' 
 > +N((*** > +N((****+ >)))4<  A% rrKKMMM/dnMMMM' r r rL'''<<<Y]YgYgYgilmnioioio(pqqqqqqqqr 4<  A% 0$*> 0#--//
*X&&&KMMMMs   A
 

B4BB!C2 2
D5<4D00D5L ,F	 H 	
GAGGH "!L #H&&$L .I: 9L :
K5J>9L >KAL Lc                     | j         S )zQHash of the downloaded file if we succeeded in downloading it, None if we failed.)r   r   s    r   hashzFileDownloader.hash   s     zr   c                     | j         S )zDList of errors if we failed to download, empty list if we succeeded.)r   r[   s    r   errorszFileDownloader.errors   s     |r   r"   )
__name__
__module____qualname__r   r   	coroutinerY   propertyr\   r^    r   r   r	   r	      s            	]b b ]bH   X   X  r   r	   )
__future__r   r   tornador   r   r   "anaconda_project.internal.makedirsinternalrG    anaconda_project.internal.renamerS   r$   rL   objectr	   rd   r   r   <module>rk      s    7 6 6 6 6 6 6 6                   5 5 5 5 5 5 5 5 5 1 1 1 1 1 1 1 1 1 				 { { { { {V { { { { {r   