
    DIe%                     L   d Z ddlZddlZddlZddlmZmZ ddlmZm	Z	m
Z
 ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZmZmZmZmZmZmZ ddlmZ ddlmZm Z m!Z!m"Z"m#Z#m$Z$ ddl%m&Z&  ee'          Z(d Z) ed          	 	 	 	 dd            Z*d Z+ G d d          Z,dS )z.Download logic for conda indices and packages.    N)DEBUG	getLogger)basenameexistsjoin   )
CondaError)dals)	stringify)context)time_recorder)BasicClobberErrorChecksumMismatchErrorCondaDependencyErrorCondaHTTPErrorCondaSSLError
ProxyErrormaybe_raise   )rm_rf   )ConnectionError	HTTPErrorInsecureRequestWarningInvalidSchemaRequestsProxyErrorSSLError)get_sessionc                  :    t          j        dt                     d S )Nignore)warningssimplefilterr        Blib/python3.11/site-packages/conda/gateways/connection/download.pydisable_ssl_verify_warningr&   &   s    ($:;;;;;r$   downloadc                    t          |          r)t          t          || t                    t                     t          j        st                       	 t          j        t          j        f}t          |           }|	                    | d|j
        |          }t                              t                    r)t                              t          |d                     |                                 t#          |j        	                    dd                    }	d x}
x}}|rt'          j        d          }
d}|}n|r|rt'          j        d          nd }
d}|}d}	 t+          |d	          5 }d}|                    d
          D ]}|j                                        }	 |                    |           n+# t4          $ r}d}t7          |||j                  d }~ww xY w|
o|
                    |           |t=          |          z  }|	r d|cxk    r|	k    rn |r |||	z             	 d d d            n# 1 swxY w Y   |	r)||	k    r#t?          d          }t7          || ||	|          n;# t4          $ r.}|j        dk    rt                              d|z              d }~ww xY w|rK|
                                 }||k    r1t                              d|| ||           tC          | ||||          |8|}||k    r2t                              d| ||           tC          | |d||          d S d S # tD          $ r tG                      tH          $ r5}dtK          |          v rt?          d          }tM          |           d }~wtN          $ rX}	 dd l(}tS          t?          d| d                    # tT          $ r! tS          t?          d| d                    w xY wd }~wtV          tX          f$ rk}t?          d          }t[          || t]          |j/        dd           t]          |j/        dd           t]          |j/        dd           |j/        |          d }~ww xY w)NTstreamproxiestimeout   content_max_lenzContent-Lengthr   sha256md5wbi @  z5Failed to write to %(target_path)s
  errno: %(errno)d)target_patherrnoa  
                Downloaded bytes did not match Content-Length
                  url: %(url)s
                  target_path: %(target_path)s
                  Content-Length: %(content_length)d
                  downloaded bytes: %(downloaded_bytes)d
                )urlr3   content_lengthdownloaded_bytesh   z%s, trying againz'%s mismatch for download: %s (%s != %s)z)size mismatch for download: %s (%s != %s)sizeSOCKSQ  
                Requests has identified that your current working environment is configured
                to use a SOCKS proxy, but pysocks is not installed.  To proceed, remove your
                proxy configuration, run `conda install pysocks`, and then you can re-enable
                your proxy configuration.
                z}
                    Encountered an SSL error. Most likely a certificate verification issue.

                    Exception: z
                    z
                    OpenSSL appears to be unavailable on this machine. OpenSSL is required to
                    download and install packages.

                    Exception: z
        An HTTP error occurred when trying to retrieve this URL.
        HTTP errors are often intermittent, and a simple retry will get you on your way.
        status_codereasonelapsed	caused_by)0r   r   r   r   
ssl_verifyr&   remote_connect_timeout_secsremote_read_timeout_secsr   getr+   logisEnabledForr   debugr   raise_for_statusintheadershashlibnewopeniter_contentrawtellwriteOSErrorr	   r4   updatelenr
   	hexdigestr   r   r   r   strr   r   sslr   ImportErrorr   r   r   getattrresponse)r5   target_full_pathr1   r0   r9   progress_update_callbackr,   sessionrespr6   checksum_builderchecksum_typechecksumsize_builderfhstreamed_byteschunkemessageactual_checksumactual_sizerW   help_messages                          r%   r'   r'   *   s     P%&6WEEwOOO %"$$$Y
5w7WWc""{{3tW_g{VVE"" 	<IIic:::;;;T\--.>BBCC 7;::=8 	&{844$MHH 	58Bw{5111d!MH0	&-- V!"!..u55 V VE &*X]]__N	"   T   )#1A    %G)9)@)@)G)G CJJ.L% V!~*O*O*O*O*O*O*O*O*O3 V44^n5TUUU)VV V V V V V V V V V V V V V V0  .N"B"B  ! 0#1%3     	 	 	w#~~		,q0111		  	.88::O(**		=!#   ,)=(O   &Kd""		?kSW   ,)64   ""    ll   c!ff G 'w///   	JJJ   !"       
	 
	 
	 !"	   	 	 	
	, Y' 
 
 

 
 AJt44AJ$//AJ	400J
 
 
 	

s   D
L: I4 /3H=#F98H=9
G!GG!!AH=1I4 =II4 I.I4 3L: 4
J,>)J''J,,B
L: :!Q*0NQ*N= O+=+O((O++Q*?A&Q%%Q*c                 l   t           j        st                       	 t           j        t           j        f}t          |           }|                    | d|j        |          }t          	                    t                    r)t                              t          |d                     |                                 n# t          $ r t                      t           $ r5}dt#          |          v rt%          d          }t'          |           d }~wt(          t*          t,          f$ r}t/          |j        dd           }|dk    rt%          d	          }nt%          d
          }t3          || |t/          |j        dd           t/          |j        dd           |j        |          d }~ww xY w|j        S )NTr)   r-   r.   r:   r;   r<   i  zv
            An HTTP error occurred when trying to retrieve this URL.
            The URL does not exist.
            z
            An HTTP error occurred when trying to retrieve this URL.
            HTTP errors are often intermittent, and a simple retry will get you on your way.
            r=   r>   r?   )r   rA   r&   rB   rC   r   rD   r+   rE   rF   r   rG   r   rH   r   r   r   rV   r
   r   r   r   r   rY   rZ   r   text)r5   r,   r]   rZ   rf   rg   r<   rj   s           r%   download_textrm      s    %"$$$0
5w7WWc"";;gow  
 
 E"" 	@IIi#>>>???!!####   ll   c!ff G 'w///Y1 
 
 
aj->># LL   L AJ$//AJ	400J
 
 
 	
!
2 =s%   B!B> >!F,0DF,)A>F''F,c                   &    e Zd ZdZddZd Zd ZdS )TmpDownloadz2Context manager to handle downloads to a tempfile.Tc                 "    || _         || _        d S N)r5   verbose)selfr5   rr   s      r%   __init__zTmpDownload.__init__  s    r$   c                     d| j         vrd | _        | j         S t          j                    | _        t	          | j        t          | j                             }t          | j         |           |S )Nz://)r5   tmp_dirtempfilemkdtempr   r   r'   )rs   dsts     r%   	__enter__zTmpDownload.__enter__  s_      DL8O#+--DLt|Xdh%7%788CTXs###Jr$   c                 @    | j         rt          | j                    d S d S rq   )rv   r   )rs   exc_type	exc_value	tracebacks       r%   __exit__zTmpDownload.__exit__  s,    < 	 $,	  	 r$   N)T)__name__
__module____qualname____doc__rt   rz   r   r#   r$   r%   ro   ro     sL        <<   	 	 	         r$   ro   )NNNN)-r   rK   rw   r!   loggingr   r   os.pathr   r   r    r	   
auxlib.ishr
   auxlib.logzr   base.contextr   	common.ior   
exceptionsr   r   r   r   r   r   r   disk.deleter   r   r   r   r   r   r   r]   r   r   rE   r&   r'   rm   ro   r#   r$   r%   <module>r      s(   5 4    $ $ $ $ $ $ $ $ * * * * * * * * * *             $ $ $ $ $ $ # # # # # # & & & & & &                                        !          i< < < z 		!f
 f
 f
 f
R4 4 4n                   r$   