
    e{@                        d Z ddl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mZmZmZ ddlmZmZ ddlmZ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 dd
l m!Z!  ee"          Z#da$ G d de          Z% G d de          Z& G d de&          Z' G d de&          Z( G d de&          Z)de&fdZ*dee+         dee+         dee!         fdZ, G d de          Z-dS )zNetwork Authentication Helpers

Contains interface (MultiDomainBasicAuth) and associated glue code for
providing credentials in the context of network requests.
    N)ABCabstractmethod)AnyDictList
NamedTupleOptionalTuple)AuthBaseHTTPBasicAuth)RequestResponse)get_netrc_auth)	getLogger)ask	ask_inputask_passwordremove_auth_from_urlsplit_auth_netloc_from_url)AuthInfoFc                   .    e Zd ZU eed<   eed<   eed<   dS )CredentialsurlusernamepasswordN)__name__
__module____qualname__str__annotations__     Q/var/www/html/api/venv/lib/python3.11/site-packages/pip/_internal/network/auth.pyr   r   !   s+         	HHHMMMMMMMMr"   r   c            	       v    e Zd ZdZededee         dee         fd            Zededededdfd            Z	dS )	KeyRingBaseProviderzKeyring base provider interfacer   r   returnc                     d S Nr!   selfr   r   s      r#   get_auth_infoz!KeyRingBaseProvider.get_auth_info*       r"   r   Nc                     d S r(   r!   r*   r   r   r   s       r#   save_auth_infoz"KeyRingBaseProvider.save_auth_info.   r,   r"   )
r   r   r   __doc__r   r   r	   r   r+   r/   r!   r"   r#   r%   r%   '   s        ))  (8BT    ^ #       ^  r"   r%   c                   V    e Zd ZdZdedee         dee         fdZdedededdfdZdS )	KeyRingNullProviderzKeyring null providerr   r   r&   c                     d S r(   r!   r)   s      r#   r+   z!KeyRingNullProvider.get_auth_info6       tr"   r   Nc                     d S r(   r!   r.   s       r#   r/   z"KeyRingNullProvider.save_auth_info9   r4   r"   )	r   r   r   r0   r   r	   r   r+   r/   r!   r"   r#   r2   r2   3   s|          (8BT    #         r"   r2   c                   ^    e Zd ZdZd
dZdedee         dee         fdZdedededdfd	Z	dS )KeyRingPythonProviderz7Keyring interface which uses locally imported `keyring`r&   Nc                     dd l }|| _         d S )Nr   keyring)r*   r:   s     r#   __init__zKeyRingPythonProvider.__init__@   s    r"   r   r   c                 <   t          | j        d          rHt                              d|           | j                            ||          }||j        |j        fS d S |<t                              d|           | j                            ||          }|r||fS d S )Nget_credentialz'Getting credentials from keyring for %sz$Getting password from keyring for %s)hasattrr:   loggerdebugr=   r   r   get_password)r*   r   r   credr   s        r#   r+   z#KeyRingPythonProvider.get_auth_infoE   s     4<!122 	LLBCHHH<..sH==D}dm334LL?EEE|00h??H *))tr"   r   c                 >    | j                             |||           d S r(   )r:   set_passwordr.   s       r#   r/   z$KeyRingPythonProvider.save_auth_infoW   s"    !!#x:::::r"   )r&   N)
r   r   r   r0   r;   r   r	   r   r+   r/   r!   r"   r#   r7   r7   =   s        AA   
  (8BT    $;# ; ; ; ; ; ; ; ; ;r"   r7   c                       e Zd ZdZdeddfdZdedee         dee         fdZdeded	eddfd
Z	dededee         fdZ
deded	eddfdZdS )KeyRingCliProviderzProvider which uses `keyring` cli

    Instead of calling the keyring package installed alongside pip
    we call keyring on the command line which will enable pip to
    use which ever installation of keyring is available first in
    PATH.
    cmdr&   Nc                     || _         d S r(   r9   )r*   rG   s     r#   r;   zKeyRingCliProvider.__init__d   s    r"   r   r   c                 B    ||                      ||          }|||fS d S r(   )_get_passwordr.   s       r#   r+   z KeyRingCliProvider.get_auth_infog   s5     ))#x88H#))tr"   r   c                 0    |                      |||          S r(   )_set_passwordr.   s       r#   r/   z!KeyRingCliProvider.save_auth_infop   s    !!#x:::r"   service_namec                 4   | j         dS | j         d||g}t          j                                        }d|d<   t	          j        |t          j        d|          }|j        rdS |j        	                    d          
                    t          j                  S )z;Mirror the implementation of keyring.get_password using cliNgetutf-8PYTHONIOENCODINGT)stdincapture_outputenv)r:   osenvironcopy
subprocessrunDEVNULL
returncodestdoutdecodestriplinesep)r*   rM   r   rG   rT   ress         r#   rJ   z KeyRingCliProvider._get_passwords   s    <4|UL(;joo")n$	
 
 
 > 	4z  ))//
;;;r"   c                    | j         dS | j         d||g}|t          j        z                       d          }t          j                                        }d|d<   t          j        |||          }|                                 dS )z;Mirror the implementation of keyring.set_password using cliNsetrP   rQ   )inputrT   )	r:   rU   r_   encoderV   rW   rX   rY   check_returncode)r*   rM   r   r   rG   input_rT   r`   s           r#   rL   z KeyRingCliProvider._set_password   s    <4|UL(;RZ'//88joo")nSC888tr"   )r   r   r   r0   r   r;   r	   r   r+   r/   rJ   rL   r!   r"   r#   rF   rF   [   s         C D      (8BT    ;# ; ; ; ; ; ; ;<# < <# < < < <$#   PT      r"   rF   r&   c                  (   t           s~	 t                      S # t          $ r Y n>t          $ r2} t                              dt          |                      Y d } ~ nd } ~ ww xY wt          j        d          }|rt          |          S t                      S )NzdInstalled copy of keyring fails with exception %s, trying to find a keyring executable as a fallbackr:   )KEYRING_DISABLEDr7   ImportError	Exceptionr?   warningr   shutilwhichrF   r2   )excclis     r#   get_keyring_providerrp      s     +	(*** 	 	 	D 	 	 	 NNDC       	 l9%% 	+%c***   s    
A	A(AAr   r   c                     | sdS t                      }	 |                    | |          S # t          $ r5}t                              dt          |                     daY d}~dS d}~ww xY w)z3Return the tuple auth for a given url from keyring.Nz*Keyring is skipped due to an exception: %sT)rp   r+   rj   r?   rk   r   rh   )r   r   r:   rn   s       r#   get_keyring_authrr      s      t"$$G	$$S(333   8HH	
 	
 	

  ttttts   * 
A)*A$$A)c            	       D   e Zd Z	 ddedeee                  ddfdZdedee         fdZ	 	 dd
ededede	fdZ
d
edeeee         ee         f         fdZdedefdZdedeee         ee         ef         fdZdefdZdededefdZdededdfdZdededdfdZdS )MultiDomainBasicAuthTN	prompting
index_urlsr&   c                 >    || _         || _        i | _        d | _        d S r(   )ru   rv   	passwords_credentials_to_save)r*   ru   rv   s      r#   r;   zMultiDomainBasicAuth.__init__   s*     #$.0 <@!!!r"   r   c                     |r| j         sdS | j         D ]@}t          |                              d          dz   }|                    |          r|c S AdS )a  Return the original index URL matching the requested URL.

        Cached or dynamically generated credentials may work against
        the original index URL rather than just the netloc.

        The provided url should have had its username and password
        removed already. If the original index url had credentials then
        they will be included in the return value.

        Returns None if no matching index was found, or if --no-index
        was specified by the user.
        N/)rv   r   rstrip
startswith)r*   r   uprefixs       r#   _get_index_urlz#MultiDomainBasicAuth._get_index_url   sr      	$/ 	4 	 	A)!,,33C883>F~~f%% tr"   Foriginal_urlallow_netrcallow_keyringc                 P   t          |          \  }}}|\  }}||t                              d|           |S |                     |          }	|	r2t          |	          }
|
r!|
\  }	}}t                              d|	           |	r.|d         &|\  }}||t                              d|           |S |r.t	          |          }|rt                              d|           |S |r?t          |	|          pt          ||          }|rt                              d|           |S ||fS )z2Find and return credentials for the specified URL.NzFound credentials in url for %szFound index url %sr   z%Found credentials in index url for %sz!Found credentials in netrc for %sz#Found credentials in keyring for %s)r   r?   r@   r   r   rr   )r*   r   r   r   r   netlocurl_user_passwordr   r   	index_url
index_info_index_url_user_password
netrc_authkr_auths                  r#   _get_new_credentialsz)MultiDomainBasicAuth._get_new_credentials   s    *D*
 *
&V&
 /(H$8LL:FCCC$$ '',,	 	>3I>>J >8B5	1519===  	/03?!8Hh#(<DfMMM..  	"'55J "@&III!!  
	 !H55 3 22 
  BFKKK!!r"   c                    t          |          \  }}}|                     |          \  }}||%|| j        v r| j        |         \  }}|||k    r||}}|||pd}|pd}||f| j        |<   ||||J d|             |||fS )a_  Return the credentials to use for the provided URL.

        If allowed, netrc and keyring may be used to obtain the
        correct credentials.

        Returns (url_without_credentials, username, password). Note
        that even if the original URL contains credentials, this
        function may return a different username and password.
        N z%Could not load credentials from url: )r   r   rx   )	r*   r   r   r   r   r   r   unpws	            r#   _get_url_and_credentialsz-MultiDomainBasicAuth._get_url_and_credentials  s     4LAAVQ "66|DD(  0f6N6N^F+FB 8r>>%'(8#7
  ~2H~2H '/%9DN6" !h&: X%5%5A<AA &6%5%5 Hh&&r"   reqc                     |                      |j                  \  }}}||_        || t          ||          |          }|                    d| j                   |S )Nresponse)r   r   r   register_hook
handle_401)r*   r   r   r   r   s        r#   __call__zMultiDomainBasicAuth.__call__K  sj    "&"?"?"H"HXx H$83-(33C88C 	*do666
r"   r   c                     t          d| d          }|sdS t          ||          }|r!|d         |d         |d         |d         dfS t          d          }||dfS )	Nz	User for z: )NNFr      Fz
Password: T)r   rr   r   )r*   r   r   authr   s        r#   _prompt_for_passwordz)MultiDomainBasicAuth._prompt_for_password\  s     333344 	%$$11 	+DG'DG,?7DGU**--4''r"   c                 N    t                      dS t          dddg          dk    S )NFz#Save credentials to keyring [y/N]: yn)rp   r   )r*   s    r#    _should_save_password_to_keyringz5MultiDomainBasicAuth._should_save_password_to_keyringi  s-    !!)583*EELLr"   respkwargsc                    |j         dk    r|S | j        s|S t          j                            |j                  }|                     |j        dd          \  }}d}|s |s|                     |j                  \  }}}d | _	        |E|C||f| j
        |j        <   |r0|                                 rt          |j        ||          | _	        |j         |j                                          t!          |pd|pd          |j                  }|                    d| j                   | j	        r|                    d| j                    |j        j        |fi |}|j                            |           |S )N  FT)r   r   )r   r   r   r   r   )status_coderu   urllibparseurlparser   r   r   r   ry   rx   r   r   contentrawrelease_connr   requestr   warn_on_401save_credentials
connectionsendhistoryappend)	r*   r   r   parsedr   r   saver   new_resps	            r#   r   zMultiDomainBasicAuth.handle_401n  s    s""K ~ 	K&&tx00 "66H 7 
 
(  	P 	P'+'@'@'O'O$Hh %)!H$8-5x,@DN6=)  ==?? ,7%%- - -) 	 <mHNHN;;DLII*d&6777
 $ 	Aj$*?@@@ (4?'66v66%%%r"   c                 j    |j         dk    r't                              d|j        j                   dS dS )z6Response callback to warn about incorrect credentials.r   z)401 Error, Credentials not correct for %sN)r   r?   rk   r   r   )r*   r   r   s      r#   r   z MultiDomainBasicAuth.warn_on_401  sC    s""NN;      #"r"   c                 v   t                      }t          |t                    r
J d            | j        }d| _        |ry|j        dk     rp	 t
                              d           |                    |j        |j	        |j
                   dS # t          $ r t
                              d           Y dS w xY wdS dS )z1Response callback to save credentials on success.z'should never reach here without keyringNi  zSaving credentials to keyringzFailed to save credentials)rp   
isinstancer2   ry   r   r?   infor/   r   r   r   rj   	exception)r*   r   r   r:   credss        r#   r   z%MultiDomainBasicAuth.save_credentials  s    &(((
 
 	5 	54	5 	5 	5 )$(! 	?T%++?;<<<&&uy%.%.QQQQQ ? ? ?  !=>>>>>>?		? 	?++s   
A B $B43B4)TN)TF)r   r   r   boolr	   r   r   r;   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r!   r"   r#   rt   rt      s       HL@ @@2:492E@	@ @ @ @# (3-    2 !#	6" 6"6" 6" 	6"
 
6" 6" 6" 6"p.'.'	sHSM8C=0	1.' .' .' .'`G     "
(
(	x}hsmT1	2
( 
( 
( 
(M$ M M M M
8x 83 88 8 8 8 8t C D    ?X ? ? ? ? ? ? ? ?r"   rt   ).r0   rU   rl   rX   urllib.parser   abcr   r   typingr   r   r   r   r	   r
   pip._vendor.requests.authr   r   pip._vendor.requests.modelsr   r   pip._vendor.requests.utilsr   pip._internal.utils.loggingr   pip._internal.utils.miscr   r   r   r   r    pip._internal.vcs.versioncontrolr   r   r?   rh   r   r%   r2   r7   rF   rp   r   rr   rt   r!   r"   r#   <module>r      s    
			          # # # # # # # # ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? = = = = = = = = 9 9 9 9 9 9 9 9 5 5 5 5 5 5 1 1 1 1 1 1              6 5 5 5 5 5	8		     *   	 	 	 	 	# 	 	 	    -   ; ; ; ; ;/ ; ; ;<5 5 5 5 5, 5 5 5p!1 ! ! ! !2(3- 8C= XhEW    &? ? ? ? ?8 ? ? ? ? ?r"   