
    siu?                       S r SSKJr  SSKrSSKrSSKrSSKrSSKJr  SSK	J
r
Jr  SSKJrJrJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJrJr  SSKJr  SSKJr  SSKJ r   SSK!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)  SSK*J+r+  SSK,J-r-  SSK.J/r/  SSKJ0r0J1r1J2r2J3r3J4r4J5r5  SSK6J7r7  \" \85      r9Sr:S r;\" S5          S"S j5       r<S r=\          S#S j5       r>\S$S j5       r?S r@ " S  S!5      rAg)%z.Download logic for conda indices and packages.    )annotationsN)contextmanager)DEBUG	getLogger)basenameexistsjoin)Path   )
CondaError)dals)	stringify)CONDA_HOMEPAGE_URLPARTIAL_EXTENSION)context)time_recorder)join_url)BasicClobberErrorChecksumMismatchErrorCondaDependencyErrorCondaHTTPErrorCondaSSLErrorCondaValueError
ProxyErrormaybe_raise)Channel   )rm_rf)lock   )ConnectionError	HTTPErrorInsecureRequestWarningInvalidSchemaRequestsProxyErrorSSLError)get_sessioni @  c                 :    [         R                  " S[        5        g )Nignore)warningssimplefilterr#        Blib/python3.13/site-packages/conda/gateways/connection/download.pydisable_ssl_verify_warningr/   4   s    ($:;r-   downloadc           
        [        U5      (       a  [        [        X[        5      [        5        [        R                  (       d
  [        5         [        U 5          [        XX#XE5        S S S 5        g ! [         aB  nUR                  S   (       d  e [        R                  SU5        [        XX#XE5         S nANPS nAff = f! , (       d  f       g = f)Npartial_downloadz Retry failed partial download %s)r   r   r   r   
ssl_verifyr/   download_http_errorsdownload_innerr   _kwargslogwarning)urltarget_full_pathmd5sha256sizeprogress_update_callbackes          r.   r0   r0   8   s     %&6WEwO"$	c	"	sD 
#	"
 % 	99/0KK:<LMsD 	 
#	"s0   C A11
B=;8B83C 8B==C  
Cc           	     *   [         R                  [         R                  4n[        U 5      nSnU(       a  U(       d  U(       a  SnSn	Sn
[	        XX#US9 n[
        R                  " UR                  5       5      nUb  UR                  U:  a
   S S S 5        g 0 nU(       a=  UR                  S:  a-  SSUR                   S30nUR                  UR                  5        UR                  U SXR                  US9n[        R                  [        5      (       a  [        R                  [!        US	S
95        UR#                  5         U(       a1  UR$                  S:w  a!  UR                  S5        UR'                  5         [)        UR*                  R                  SS5      5      =nnU(       aT  U(       aM  UR*                  R                  SS5      n [)        UR-                  SS5      S   R/                  S5      S   5      nUR5                  [6        S9 Hz  nUR8                  R;                  5       n	 UR=                  U5        U
[G        U5      -  n
U(       d  MF  SU	s=::  a  U::  d  MU  O  MY  U(       d  Mb  U" UR                  U	-   U-  5        M|     U(       a  X:w  a  [I        S5      n[A        UU UUU	S9eS S S 5        g ! [0        [2        4 a     Nf = f! [>         a&  nSn[A        UURB                  URD                  S9eS nAff = f! , (       d  f       g = f)NFTr   )r9   r;   r<   r=   Rangezbytes=-)streamheadersproxiestimeout   content_max_len   zContent-LengthzContent-Rangezbytes 0-0/0 r    /)
chunk_sizez5Failed to write to %(target_path)s
  errno: %(errno)d)target_patherrnoz
            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
            )r9   rO   content_lengthdownloaded_bytes)%r   remote_connect_timeout_secsremote_read_timeout_secsr'   download_partial_fileosfstatfilenost_sizeseekgetrE   r7   isEnabledForr   debugr   raise_for_statusstatus_codetruncateintrD   splitrsplitLookupError
ValueErroriter_content
CHUNK_SIZErawtellwriteOSErrorr   namerP   lenr   )r9   r:   r;   r<   r=   r>   rF   sessionpartialstreamed_bytessize_buildertargetstat_resultrD   resprQ   total_content_lengthcontent_rangechunkr?   messages                        r.   r5   r5   U   s   1173S3SSG#GGNL 
s
	hhv}}/ 3 3t ;
 
 {**Q.&)<)<(=Q ?@GKK++,{{gPW  
 E""IIic:; t''3.KKNOO03LL-q11
 	
- w !LL,,_mLM'*!''Q/299#>rB($ &&*&=E "XX]]_NRU# CJ&L##^(M~(M(M++,$,,~=AUU >" n>G ,-!/ G
 
H  ,   RR fkkQQR[
 
sn   9LD6L0J;=0L.K?LL%	L2A L;KLKL
L!K<<LL
Lc             #  ,  ^ ^^^^^#    [        T 5      m T R                  n[        T 5      R                  nU [         3nXW-  nUR	                  5       mT(       a  SOSn	UUUUU U4S jn
 UR                  U	S9 n[        U5         Uv   U
" U5        SSS5        SSS5         UR                  T 5        g! , (       d  f       N)= f! , (       d  f       N2= f! [         ae  n UR                  R                  nO! [         a    Sn Of = f[        U[        5      (       a   SUs=::  a  S:  a  O  e UR                  5         e SnAf[         a    UR                  5         e f = f! [          a$    T R                  5         UR                  T 5         gf = f7f)z~
Create or open locked partial download file, moving onto target_full_path
when finished. Preserve partial file on exception.
zr+bzw+bc           	       > U R                  S5        T	(       d  T(       a  T(       a  SOSnT(       a  TOT	n [        R                  U5      n[        R                  " U5      nU R                  S5        U R                  [        5      =n(       a/  UR                  U5        U R                  [        5      =n(       a  M/  UR                  5       U:w  a7  UR                  5       n[        R                  SUTUU5        [        TTUUUT
S9eTb[  [         R"                  " U R%                  5       5      R&                  nUT:w  a&  [        R                  STUT5        [        TTSTUT
S9eg g ! [        [        4 a  n[        U5      UeS nAff = f)Nr   r<   r;   z'%s mismatch for download: %s (%s != %s))r2   z)size mismatch for download: %s (%s != %s)r=   )rZ   bytesfromhexre   	TypeErrorr   hashlibnewreadrg   updatedigest	hexdigestr7   r]   r   rV   rW   rX   rY   )rr   checksum_typechecksumchecksum_bytesexchasherr   actual_checksumactual_sizer;   r2   r<   r=   r:   r9   s            r.   check$download_partial_file.<locals>.check   st   A&(.HEM!'vSH4!&x!8 [[/FKKN ++j11$1d# !++j11$1 }}.0"("2"2"4		=!# ,$!#%5  ((6==?3;;Kd"		?	 ,$%5  # 1 	* 4%c*34s   E) )F
9FF
)modeNi  i  )r
   parentrl   r   r   openr   r"   responser_   AttributeError
isinstancera   unlinkr   renamerk   )r:   r9   r<   r;   r=   r   rl   partial_namepartial_pathr   r   ro   r?   r_   r2   s   `````         @r.   rU   rU      sk     ,-$$F !&&DV-./L(L $**,$5%D/ /bD)Wd7mM'N 7D)".,-% 7Dm))  		**00K 	K	k3''C;,D,D !    .!,-.s   A!F*C 9CB5CC #E# 4F5
C	?C
CC FC 
E "C98E9DED9EE  F#+FFFFc              #    #     Sv   g! [          a  n[        R                  U S35        e SnAf[         a    [	        5       e[
         a+  nS[        U5      ;   a  [        S5      n[        U5      ee SnAf[         aH  n SSK
n[        [        SU S35      5      e! [         a    [        [        SU S35      5      ef = fSnAf[        [        4 Ga  n[        UR                   S	S5      nUS
:X  a  [#        U 5      nUR$                  (       a  [        S['        [(        S5       S35      nO[*        R,                  R.                  U ;   a  [        S['        [(        S5       S35      nO[        S['        [(        S5       S35      nOUS:X  a  [#        U 5      nUR$                  (       a  [        S['        [(        S5       S35      nOe[*        R,                  R.                  U ;   a  [        S['        [(        S5       S35      nO)[        S['        [(        S5       S35      nO[        S5      n[1        UU U[        UR                   SS5      [        UR                   SS5      UR                   US9eSnAff = f7f)z+Exception translator used inside download()Nz, trying againSOCKSaQ  
                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.
                r   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: r_   i  a  
                    The token given for the URL has insufficient permissions to access this resource.

                    You may not have the required permissions to access this channel or package.
                    Consider requesting access from the channel owner.

                    Use `conda config --show` to view your configuration's current state.
                    Further configuration help can be found at <zdocs/config.htmlz>.
                    a$  
                    The remote server has indicated you do not have permission to access this resource.

                    This may mean:
                      (a) You are not authenticated. Check if authentication is required for this channel
                          and verify your credentials are correctly configured.
                      (b) You do not have access to this private channel or package. Contact the
                          channel owner to request access.

                    Further configuration help can be found at <a  
                    You do not have permission to access this resource.

                    This may indicate:
                      - The channel requires authentication. Check your credentials.
                      - You do not have access to this private channel or package.

                    You will need to modify your conda configuration to proceed.
                    Use `conda config --show` to view your configuration's current state.
                    Further configuration help can be found at <i  a*  
                    The token given for the URL is invalid.

                    You will need to adjust your conda configuration to proceed.

                    Use `conda config --show` to view your configuration's current state.
                    Further configuration help can be found at <an  
                    The remote server has indicated you are using invalid credentials for this channel.

                    You may need to:
                      (a) Remove or update the invalid token from your configuration, or
                      (b) Provide conda with a valid token directly.

                    Further configuration help can be found at <a=  
                    The credentials you have provided for this URL are invalid.

                    You will need to modify your conda configuration to proceed.
                    Use `conda config --show` to view your configuration's current state.
                    Further configuration help can be found at <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.
                reasonelapsed)	caused_by)ConnectionResetErrorr7   r]   r%   r   r$   strr   r   r&   sslr   ImportErrorr!   r"   getattrr   r   tokenr   r   r   channel_aliaslocationr   )r9   r?   rx   r   r_   channelhelp_messages          r.   r4   r4     s    U
 		QC~&' l c!fG 'w// 	    !"s #   
	  !"s #		 	
	, Y' b
ajj->#clG}}#A BJJ\^pAq@r s
  &&//36#	A BJJ\^pAq@r s
   $	A BJJ\^pAq@r s
  CclG}}#A BJJ\^pAq@r s	  &&//36#A BJJ\^pAq@r s
   $A
 BJJ\^pAq@r s   L AJJ$/AJJ	40JJ
 	
ub
sY   I7	 I7
I4, I4&A22I4 BC#B??CI4FI//I44I7c                   [         R                  (       d
  [        5         [        U 5         [         R                  [         R
                  4n[        U 5      nUR                  U SUR                  US9n[        R                  [        5      (       a  [        R                  [        USS95        UR                  5         S S S 5        UR                  $ ! , (       d  f       WR                  $ = f)NT)rC   rE   rF   rG   rH   )r   r3   r/   r4   rS   rT   r'   r[   rE   r7   r\   r   r]   r   r^   text)r9   rF   rn   r   s       r.   download_textr     s    "$	c	"55w7W7WWc";;goow  
 E""IIi#>?!!# 
# == 
#	" ==s   BC
C+c                  .    \ rS rSrSrSS jrS rS rSrg)	TmpDownloadi  z2Context manager to handle downloads to a tempfile.c                    Xl         X l        g N)r9   verbose)selfr9   r   s      r.   __init__TmpDownload.__init__  s    r-   c                    SU R                   ;  a  S U l        U R                   $ [        R                  " 5       U l        [	        U R                  [        U R                   5      5      n[        U R                   U5        U$ )Nz://)r9   tmp_dirtempfilemkdtempr	   r   r0   )r   dsts     r.   	__enter__TmpDownload.__enter__  sZ     DL88O#++-DLt||Xdhh%78CTXXs#Jr-   c                R    U R                   (       a  [        U R                   5        g g r   )r   r   )r   exc_type	exc_value	tracebacks       r.   __exit__TmpDownload.__exit__  s    <<$,, r-   )r   r9   r   N)T)	__name__
__module____qualname____firstlineno____doc__r   r   r   __static_attributes__r,   r-   r.   r   r     s    <	 r-   r   )NNNN)
r:   z
str | Pathr9   r   r<   r   r;   r   r=   ra   )r9   r   )Br   
__future__r   r~   rV   r   r*   
contextlibr   loggingr   r   os.pathr   r   r	   pathlibr
    r   
auxlib.ishr   auxlib.logzr   base.constantsr   r   base.contextr   	common.ior   
common.urlr   
exceptionsr   r   r   r   r   r   r   r   models.channelr   disk.deleter   	disk.lockr   r!   r"   r#   r$   r%   r&   rn   r'   r   r7   rg   r/   r0   r5   rU   r4   r   r   r,   r-   r.   <module>r      s   5 "  	   % $ * *    $ C # & "	 	 	 &    ! 
< z 		! 8Vt Y. Y.*-Y.7:Y.ADY.LOY. Y.x Z
 Z
z   r-   