
    si9                    &   S 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	  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  SSKJrJr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!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K0J1r1  \(       a  SSK2J3r3J4r4  \" \55      r6Sr7\8" S5      r9\8" / SQ5      r:\8" / SQ5      r;\8" / SQ5      r< " S S\"5      r=S+S jr>S,S  jr?\S-S! j5       r@S.S" jrA " S# S$\B5      rC " S% S&\%\CS'9rD " S( S)\!5      rEg*)/z>Requests session configured with all accepted scheme adapters.    )annotations)fnmatch)cache)	getLogger)local)TYPE_CHECKING   )
CondaError)dals)CONDA_HOMEPAGE_URL)context)add_username_and_passwordget_proxy_username_and_passsplit_anaconda_tokenurlparse)OfflineErrorPluginError
ProxyErrorChannel   )read_binstar_tokens   )	AuthBaseBaseAdapterCaseInsensitiveDictRetrySession_basic_auth_strextract_cookies_to_jarget_auth_from_urlget_netrc_auth)
FTPAdapter)HTTPAdapter)LocalFSAdapter)	S3Adapter)PreparedRequestRequest)httphttpsftps3file)zaccept-charsetzaccept-encodingzaccess-control-request-headerszaccess-control-request-method
connectionzcontent-lengthcookiedatedntexpecthostz
keep-aliveoriginrefererz
set-cookietetrailerztransfer-encodingupgradevia)zx-http-methodzx-http-method-overridezx-method-override)connecttracetrackc                  $    \ rS rSrSS jrS rSrg)EnforceUnusedAdapterc   c                4    [        SUR                   S35      e)Nz%EnforceUnusedAdapter called with url z<.
This command is using a remote connection in offline mode.)r   url)selfrequestargskwargss       Alib/python3.13/site-packages/conda/gateways/connection/session.pysendEnforceUnusedAdapter.sendd   s'    3GKK= AI I
 	
    c                    [        5       eN)NotImplementedError)rB   s    rF   closeEnforceUnusedAdapter.closej   s    !##rI    N)rC   r(   )__name__
__module____qualname____firstlineno__rG   rM   __static_attributes__rO   rI   rF   r>   r>   c   s    
$rI   r>   c                B    [         R                  " U 5      R                  $ )zG
Given a URL, determine the channel it belongs to and return its name.
)r   from_urlcanonical_name)rA   s    rF   get_channel_name_from_urlrX   n   s     C ///rI   c                   U R                  5        H  u  pUR                  5       nU[        ;   a  [        SU S35      eUR	                  S5      (       d  UR	                  S5      (       a  [        SU S35      eU[
        ;   d  Mu  [        U[        5      (       d  M  UR                  5       [        ;   d  M  [        SU SU S35      e   g	)
a  
Validate plugin-provided headers and raise PluginError if any forbidden
headers are detected. This prevents plugins from compromising conda's
core network stack.

:param headers: Dictionary of headers to validate
:raises PluginError: If any forbidden headers are detected
z*Plugin attempted to set forbidden header 'z'. This header is not allowed as it could compromise conda's network stack. See https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_request_headerzproxy-zsec-z'. Headers starting with 'Proxy-' or 'Sec-' are not allowed as they could compromise conda's network stack. See https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_request_headerz Plugin attempted to set header 'z' with forbidden method 'z'. This method override is not allowed as it could compromise conda's network stack. See https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_request_headerN)	itemslowerFORBIDDEN_HEADERSr   
startswith!FORBIDDEN_METHOD_OVERRIDE_HEADERS
isinstancestrFORBIDDEN_HTTP_METHODS)headerskeyvalue	key_lowers       rF   _validate_plugin_headersrf   u   s     mmo
IIK	))<SE Ba a  ))Y-A-A&-I-I<SE Ba a  99%%%%++-;Q*Q!6se;TUZT[ \e e ) &rI   c                t   [        U 5      nUc
  [        5       $ 0 n[        R                   H  nUR	                  SS5      nXA:X  a  UnM  [        U 5      n[        U5      nUR                  UR                  :w  a  MP  UR                  UR                  -   nUR                  UR                  -   n[        Xx5      (       d  M  UnM     UR	                  SS5      R                  5       =(       d    Sn	U	c
  [        5       $ [        R                  R                  U	5      n
U
(       d
  [        5       $ [        U
" U5      S9$ )zh
Function that determines the correct Session object to be returned
based on the URL that is passed in.
Nchannel auth)rj   )rX   CondaSessionr   channel_settingsgetr   schemenetlocpathr   stripplugin_managerget_auth_handler)rA   channel_namerl   settingsrh   
parsed_urlparsed_settingurl_without_schemapatternauth_handlerauth_handler_clss              rF   get_sessionr|      s%    -S1L ~ ,,,,y"-"' c]
!'*   J$5$55'..@ ''.*=*==%//'' -* $''399;CtL ~-->>|L~-l;<<rI   c                    U c  g[        U [        5      (       a  [        U 5      $ [        U 5      nUR                   SUR
                   SU R                   3$ )zW
Function that determines which storage key to use for our CondaSession object caching
default.z::)r_   tuplehashtyperQ   rR   rt   )rj   	auth_types     rF   get_session_storage_keyr      sX     |$DzT
I""#1Y%;%;$<Bt?P?P>QRRrI   c                  8   ^  \ rS rSrSrU 4S jrU 4S jrSrU =r$ )CondaSessionType   z
Takes advice from https://github.com/requests/requests/issues/1871#issuecomment-33327847
and creates one Session instance per thread.
c                >   > [        5       US'   [        TU ]	  XX#5      $ )N_thread_local)r   super__new__)mcsnamebasesdct	__class__s       rF   r   CondaSessionType.__new__   s     $wOws%55rI   c                :  > [        UR                  S5      5      n U R                  R                  U   $ ! [         a&    [
        TU ]  " S0 UD6nX#0U R                  l         U$ [         a,    [
        TU ]  " S0 UD6=o0R                  R                  U'    U$ f = f)Nrj   rO   )r   rm   r   sessionsAttributeErrorr   __call__KeyError)clsrE   storage_keysessionr   s       rF   r   CondaSessionType.__call__   s    -fjj.@A	$$--k:: 	@g&00G*5)?C&   	@E@P AA G''00= 	s   6 ,B%1BBrO   )	rP   rQ   rR   rS   __doc__r   r   rT   __classcell__r   s   @rF   r   r      s    
6 rI   r   c                  T   ^  \ rS rSr S SU 4S jjjrSU 4S jjr\S 5       rSrU =r	$ )	rk      c                  > [         TU ]  5         U=(       d
    [        5       U l        U R                  R                  [        R                  5        Sn[        R                  S:X  a,   SSK	nSSK
nUR                  UR                  5      nSU l        O[        R                  U l        [        R                   (       aS  [#        5       nU R%                  SU5        U R%                  SU5        U R%                  SU5        U R%                  S	U5        O['        [        R(                  [        R*                  / S
QSSS9n[-        XbS9nU R%                  SU5        U R%                  SU5        U R%                  S[/        5       5        U R%                  S	[1        5       5        U R%                  S[3        5       5        [        R4                  U R6                  S'   [        R8                  (       a&  [        R:                  [        R8                  4U l        g[        R:                  (       a  [        R:                  U l        gg! [         a    [        S5      ef = f)zI
:param auth: Optionally provide ``requests.AuthBase`` compliant objects
N
truststorer   zNThe `ssl_verify: truststore` setting is only supported onPython 3.10 or later.Tzhttp://zhttps://zftp://zs3://)i  i  i  i  F)totalbackoff_factorstatus_forcelistraise_on_statusrespect_retry_after_header)max_retriesssl_contextzfile://z
User-Agent)r   __init__CondaHttpAuthrj   proxiesupdater   proxy_servers
ssl_verifysslr   
SSLContextPROTOCOL_TLS_CLIENTImportErrorr
   verifyoffliner>   mountr   remote_max_retriesremote_backoff_factorr$   r#   r&   r%   
user_agentrb   client_ssl_cert_keyclient_ssl_certcert)	rB   rj   r   r   r   unused_adapterretryhttp_adapterr   s	           rF   r   CondaSession.__init__   s    	+MO	G112-
!(33C4K4KL DK!,,DK??13NJJy.1JJz>2JJx0JJw/ 00&<<!5 %+0E '5RLJJy,/JJz<0JJx.JJw	,

9n./%,%7%7\"&& 00'2M2MNDI$$//DI %K   , s   (#H: :Ic                  > [        UR                  5      nUR                  S;   a  [        R                  R                  UR                  S9n[        R                  R                  UR                  UR                  S9n[        U5        [        U5        [        0 UEUEUR                  =(       d    0 E5      Ul        [        TU ]5  U5      $ )N)r*   r)   )r3   )r3   rp   )r   rA   rn   r   rr   get_cached_session_headersro   get_cached_request_headersrp   rf   r   rb   r   prepare_request)rB   rC   rA   session_headersrequest_headersr   s        rF   r   CondaSession.prepare_request2  s    w{{#::**%44OOZZ P O &44OOZZchh P O
 %_5$_51% & ,"	GO w&w//rI   c                n     U R                   R                  R                  5         g ! [         a     g f = frK   )r   r   clearr   )r   s    rF   cache_clearCondaSession.cache_clearK  s1    	&&,,. 		s   $' 
44)rj   r   r   rK   )rj   z!AuthBase | tuple[str, str] | None)rC   r(   returnr'   )
rP   rQ   rR   rS   r   r   classmethodr   rT   r   r   s   @rF   rk   rk      s4     37;0/;0 ;0z02  rI   rk   )	metaclassc                  J    \ rS rSrS r\S 5       r\S 5       r\S 5       rSr	g)r   iT  c                    [         R                  UR                  5      Ul        U R                  U5        UR	                  SU R
                  5        U$ )Nresponse)r   add_binstar_tokenrA   _apply_basic_authregister_hook
handle_407)rB   rC   s     rF   r   CondaHttpAuth.__call__W  s?    #55gkkBw'j$//:rI   c                    [        U R                  5      n[        U5      (       a  UOS nUc  [        U R                  5      n[	        U[
        5      (       a$  [        U5      S:X  a  [        U6 U R                  S'   U $ )Nr   Authorization)	r!   rA   anyr"   r_   r   lenr   rb   )rC   url_authrj   s      rF   r   CondaHttpAuth._apply_basic_auth]  sc     %W[[1x==xd<!'++.DdE""s4yA~/>/EGOOO,rI   c                <   [        U 5      u  pU(       d  [        R                  (       ar  [        5       R	                  5        HV  u  p2UR                  U5      (       d  M  [        R                  SU5        SSKJ	n  U" U5      nX%l
        UR                  SS9s  $    U $ )Nz"Adding anaconda token for url <%s>r	   r   T)with_credentials)r   r   add_anaconda_tokenr   rZ   r]   logdebugmodels.channelr   tokenrA   )rA   	clean_urlr   binstar_urlr   rh   s         rF   r   CondaHttpAuth.add_binstar_tokenl  s~    /4	33&9&;&A&A&C"''44IIBIN9%i0G$)M";;;== 'D 
rI   c           	        U R                   S:w  a  U $ U R                    U R                  5         UR                  S5      n[	        U R
                  5      R                  nX2;  a   [        [        SU< S[         S35      5      eX#   n[        U5      u  pV[        XEU5      n[        XV5      nXBU'   X!S'   U R                  R                  5       n[        UR                   U R                  U R"                  5        UR%                  UR                   5        XxR&                  S'   U R(                  R*                  " U40 UD6n	U	R,                  R/                  U 5        Xl        U	$ )a  
Prompts the user for the proxy username and password and modifies the
proxy in the session object to include it.

This method is modeled after
  * requests.auth.HTTPDigestAuth.handle_401()
  * requests.auth.HTTPProxyAuth
  * the previous conda.fetch.handle_proxy_407()

It both adds 'username:password' to the proxy URL, as well as adding a
'Proxy-Authorization' header.  If any of this is incorrect, please file an issue.

i  r   z(
            Could not find a proxy for z. See
            z/docs/html#configure-conda-for-use-behind-a-proxy-server
            for more information on how to configure proxies.
            zProxy-Authorization)status_codecontentrM   popr   rA   rn   r   r   r   r   r   r   rC   copyr    _cookiesrawprepare_cookiesrb   r.   rG   historyappend)
r   rE   r   proxy_scheme	proxy_urlusernamepasswordproxy_authorization_headerprep	_responses
             rF   r   CondaHttpAuth.handle_407z  sO   $ 3&O 	**Y'-44&((4'7 8  !  )	8F-i8L	%4X%H" )#y$$&t}}h.>.>MT]]+.H*+'',,T<V<	  * rI   rO   N)
rP   rQ   rR   rS   r   staticmethodr   r   r   rT   rO   rI   rF   r   r   T  sC         8 8rI   r   N)rA   r`   r   z
str | None)rb   dictr   None)rA   r`   )r   r`   )Fr   
__future__r   r   	functoolsr   loggingr   	threadingr   typingr   ri   r
   
auxlib.ishr   base.constantsr   base.contextr   
common.urlr   r   r   r   
exceptionsr   r   r   r   r   anaconda_clientr   r   r   r   r   r   r   r    r!   r"   adapters.ftpr#   adapters.httpr$   adapters.localfsr%   adapters.s3r&   requests.modelsr'   r(   rP   r   RETRIES	frozensetCONDA_SESSION_SCHEMESr\   r^   ra   r>   rX   rf   r|   r   r   r   rk   r   rO   rI   rF   <module>r     s   E "         0 #  @ ? % 1
 
 
 % & , "8
 "   2 %.% ! ##@A $; $0!H .= .=bSt 4]7&6 ]@_H _rI   