
    <Bhn-                       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  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K/J0r0  \(       a  SSK1J2r2J3r3  \" \45      r5Sr6\7" S5      r8 " S S\!5      r9S'S jr:\S(S j5       r;S)S jr< " S S \=5      r> " S! S"\$\>S#9r? " S$ S%\ 5      r@g&)*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
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filec                  $    \ rS rSrSS jrS rSrg)EnforceUnusedAdapter<   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.send=   s'    3GKK= AI I
 	
    c                    [        5       eN)NotImplementedError)r2   s    r6   closeEnforceUnusedAdapter.closeC   s    !##r9    N)r3   r'   )__name__
__module____qualname____firstlineno__r7   r=   __static_attributes__r?   r9   r6   r.   r.   <   s    
$r9   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)r1   s    r6   get_channel_name_from_urlrH   G   s     C ///r9   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)rL   )rH   CondaSessionr   channel_settingsgetr   schemenetlocpathr   stripplugin_managerget_auth_handler)r1   channel_namerN   settingsrJ   
parsed_urlparsed_settingurl_without_schemapatternauth_handlerauth_handler_clss              r6   get_sessionr^   N   s%    -S1L ~ ,,,,y"-"' c]
!'*   J$5$55'..@ ''.*=*==%//'' -* $''399;CtL ~-->>|L~-l;<<r9   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::)
isinstancetuplehashtyperA   rB   rV   )rL   	auth_types     r6   get_session_storage_keyrg      sX     |$DzT
I""#1Y%;%;$<Bt?P?P>QRRr9   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       r6   rn   CondaSessionType.__new__   s     $wOws%55r9   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)NrL   r?   )rg   rO   rl   sessionsAttributeErrorrm   __call__KeyError)clsr5   storage_keysessionrs   s       r6   rx   CondaSessionType.__call__   s    -fjj.@A	$$--k:: 	@g&00G*5)?C&   	@E@P AA G''00= 	s   6 ,B%1BBr?   )	r@   rA   rB   rC   __doc__rn   rx   rD   __classcell__rs   s   @r6   ri   ri      s    
6 r9   ri   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	$ )	rM      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)rm   __init__CondaHttpAuthrL   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_agentheadersclient_ssl_cert_keyclient_ssl_certcert)	r2   rL   r   r   r   unused_adapterretryhttp_adapterrs   s	           r6   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                h  > [        UR                  5      nUR                  S;   a~  [        0 [        R
                  R                  UR                  S9E[        R
                  R                  UR                  UR                  S9EUR                  =(       d    0 E5      Ul
        [        TU ]1  U5      $ )N)r)   r(   )host)r   rR   )r   r1   rP   r   r   rT   get_cached_session_headersrQ   get_cached_request_headersrR   r   rm   prepare_request)r2   r3   r1   rs   s      r6   r   CondaSession.prepare_request   s    w{{#::**1	,,GG ZZ H 	
 ,,GG ZZchh H 	 ,"	GO w&w//r9   c                n     U R                   R                  R                  5         g ! [         a     g f = fr;   )rl   rv   clearrw   )rz   s    r6   cache_clearCondaSession.cache_clear   s1    	&&,,. 		s   $' 
44)rL   r   r   r;   )rL   z!AuthBase | tuple[str, str] | None)r3   r'   returnr&   )
r@   rA   rB   rC   r   r   classmethodr   rD   r   r   s   @r6   rM   rM      s4     37;0/;0 ;0z0$  r9   rM   )	metaclassc                  J    \ rS rSrS r\S 5       r\S 5       r\S 5       rSr	g)r   i  c                    [         R                  UR                  5      Ul        U R                  U5        UR	                  SU R
                  5        U$ )Nresponse)r   add_binstar_tokenr1   _apply_basic_authregister_hook
handle_407)r2   r3   s     r6   rx   CondaHttpAuth.__call__  s?    #55gkkBw'j$//:r9   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    r1   anyr!   rb   rc   lenr   r   )r3   url_authrL   s      r6   r   CondaHttpAuth._apply_basic_auth  sc     %W[[1x==xd<!'++.DdE""s4yA~/>/EGOOO,r9   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   items
startswithlogdebugmodels.channelr   tokenr1   )r1   	clean_urlr   binstar_urlr   rJ   s         r6   r   CondaHttpAuth.add_binstar_token  s~    /4	33&9&;&A&A&C"''44IIBIN9%i0G$)M";;;== 'D 
r9   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contentr=   popr   r1   rP   r   r   r   r   r   r   r3   copyr   _cookiesrawprepare_cookiesr   
connectionr7   historyappend)
r   r5   r   proxy_scheme	proxy_urlusernamepasswordproxy_authorization_headerprep	_responses
             r6   r   CondaHttpAuth.handle_407(  sO   $ 3&O 	**Y'-44&((4'7 8  !  )	8F-i8L	%4X%H" )#y$$&t}}h.>.>MT]]+.H*+'',,T<V<	  * r9   r?   N)
r@   rA   rB   rC   rx   staticmethodr   r   r   rD   r?   r9   r6   r   r     sC         8 8r9   r   N)r1   strr   z
str | None)r1   r   )r   r   )Ar~   
__future__r   r   	functoolsr   loggingr   	threadingr   typingr   rK   r
   
auxlib.ishr   base.constantsr   base.contextr   
common.urlr   r   r   r   
exceptionsr   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'   r@   r   RETRIES	frozensetCONDA_SESSION_SCHEMESr.   rH   r^   rg   re   ri   rM   r   r?   r9   r6   <module>r      s    E "         0 #  3 % 1
 
 
 % & , "8
 " $; $0 .= .=bSt 4V7&6 Vr_H _r9   