zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
U
H=®dZ-ã
@s(dZddlZddlmZmZddlmZddlmZ    ddl
m Z m Z m Z mZmZddlmZer¦ddlmZmZmZmZmZdd    lmZdd
lmZmZeeeefZe e ¡Z!z ddl"Z"WnNe#k
rÔdZ"Yn8e$k
r
Z%ze! &d ee%ƒ¡dZ"W5dZ%[%XYnXd d „Z'Gdd„deƒZ(dS)z¡Network Authentication Helpers
 
Contains interface (MultiDomainBasicAuth) and associated glue code for
providing credentials in the context of network requests.
éN)ÚAuthBaseÚ HTTPBasicAuth)Úget_netrc_auth)Úparse)ÚaskÚ    ask_inputÚ ask_passwordÚremove_auth_from_urlÚsplit_auth_netloc_from_url)ÚMYPY_CHECK_RUNNING)ÚDictÚOptionalÚTupleÚListÚAny)ÚAuthInfo)ÚResponseÚRequestú*Keyring is skipped due to an exception: %sc
CsÄ|rts dSz€z
tj}Wntk
r,Yn4Xt d|¡|||ƒ}|dk    rZ|j|jfWSWdS|rŠt d|¡t ||¡}|rŠ||fWSWn2tk
r¾}zt     dt
|ƒ¡W5d}~XYnXdS)z3Return the tuple auth for a given url from keyring.Nz'Getting credentials from keyring for %sz$Getting password from keyring for %sr) ÚkeyringÚget_credentialÚAttributeErrorÚloggerÚdebugÚusernameÚpasswordÚ get_passwordÚ    ExceptionÚwarningÚstr)ÚurlrrÚcredrÚexc©r#úQD:\z\workplace\VsCode\pyvenv\venv\Lib\site-packages\pip/_internal/network/auth.pyÚget_keyring_auth,s.
 
  ÿr%c@s`eZdZddd„Zdd„Zddd„Zd    d
„Zd d „Zd d„Zdd„Z    dd„Z
dd„Z dd„Z dS)ÚMultiDomainBasicAuthTNcCs||_||_i|_d|_dS)N)Ú    promptingÚ
index_urlsÚ    passwordsÚ_credentials_to_save)Úselfr'r(r#r#r$Ú__init__MszMultiDomainBasicAuth.__init__cCsB|r
|jsdS|jD](}t|ƒ d¡d}| |¡r|SqdS)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ú/)r(r    ÚrstripÚ
startswith)r+r ÚuÚprefixr#r#r$Ú_get_index_urlYs
 
 
 
z#MultiDomainBasicAuth._get_index_urlcCsòt|ƒ\}}}|\}}|dk    r6|dk    r6t d|¡|S| |¡}    |    rft|    ƒ}
|
rf|
\}    } } t d|    ¡|    rž| ddk    rž| \}}|dk    rž|dk    ržt d|¡| S|r¾t|ƒ} | r¾t d|¡| S|rêt|    |ƒpÔt||ƒ}|rêt d|¡|S||fS)z2Find and return credentials for the specified URL.NzFound credentials in url for %szFound index url %srz%Found credentials in index url for %sz!Found credentials in netrc for %sz#Found credentials in keyring for %s)r
rrr2rr%)r+Ú original_urlÚ allow_netrcÚ allow_keyringr ÚnetlocÚurl_user_passwordrrÚ    index_urlÚ
index_infoÚ_Úindex_url_user_passwordÚ
netrc_authÚkr_authr#r#r$Ú_get_new_credentialsps>ÿ
 
 
 
þ z)MultiDomainBasicAuth._get_new_credentialscCs¤t|ƒ\}}}|j |d¡\}}|dkr>|dkr>| |¡\}}|dk    sN|dk    rl|pTd}|p\d}||f|j|<|dk    r||dk    sš|dkrŒ|dksštd |¡ƒ‚|||fS)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.
        )NNNÚz'Could not load credentials from url: {})r
r)Úgetr>ÚAssertionErrorÚformat)r+r3r r6r:rrr#r#r$Ú_get_url_and_credentials£s& þþüüûz-MultiDomainBasicAuth._get_url_and_credentialscCsH| |j¡\}}}||_|dk    r6|dk    r6t||ƒ|ƒ}| d|j¡|S)NÚresponse)rCr rÚ register_hookÚ
handle_401)r+Úreqr rrr#r#r$Ú__call__Ìs zMultiDomainBasicAuth.__call__cCs`td |¡ƒ}|sdSt||ƒ}|rN|ddk    rN|ddk    rN|d|ddfStdƒ}||dfS)Nz User for {}: )NNFréFz
Password: T)rrBr%r)r+r6rÚauthrr#r#r$Ú_prompt_for_passwordÞs
z)MultiDomainBasicAuth._prompt_for_passwordcCstsdStdddgƒdkS)NFz#Save credentials to keyring [y/N]: ÚyÚn)rr)r+r#r#r$Ú _should_save_password_to_keyringêsz5MultiDomainBasicAuth._should_save_password_to_keyringc    Ksà|jdkr|S|js|St |j¡}| |j¡\}}}d|_|dk    rv|dk    rv||f|j|j<|rv|     ¡rv|j||f|_|j
|j   ¡t |pŽd|p”dƒ|jƒ}| d|j¡|jrÀ| d|j¡|jj|f|Ž}|j |¡|S)Né‘r?rD)Ú status_coder'Ú urllib_parseÚurlparser rKr6r*r)rNÚcontentÚrawÚ release_connrÚrequestrEÚ warn_on_401Úsave_credentialsÚ
connectionÚsendÚhistoryÚappend)    r+ÚrespÚkwargsÚparsedrrÚsaverGÚnew_respr#r#r$rFðs(
 
 zMultiDomainBasicAuth.handle_401cKs|jdkrt d|jj¡dS)z6Response callback to warn about incorrect credentials.rOz)401 Error, Credentials not correct for %sN)rPrrrVr )r+r]r^r#r#r$rWs
 
ÿz MultiDomainBasicAuth.warn_on_401cKsntdk    stdƒ‚tsdS|j}d|_|rj|jdkrjzt d¡tj|ŽWntk
rht d¡YnXdS)z1Response callback to save credentials on success.Nz'should never reach here without keyringizSaving credentials to keyringzFailed to save credentials)    rrAr*rPrÚinfoÚ set_passwordrÚ    exception)r+r]r^Úcredsr#r#r$rX&s
z%MultiDomainBasicAuth.save_credentials)TN)TT) Ú__name__Ú
__module__Ú __qualname__r,r2r>rCrHrKrNrFrWrXr#r#r#r$r&Ks
ÿ
3) .r&))Ú__doc__ÚloggingZpip._vendor.requests.authrrZpip._vendor.requests.utilsrZpip._vendor.six.moves.urllibrrQÚpip._internal.utils.miscrrrr    r
Úpip._internal.utils.typingr Útypingr r rrrÚ pip._internal.vcs.versioncontrolrZpip._vendor.requests.modelsrrrZ CredentialsÚ    getLoggerrfrrÚ ImportErrorrr"rr%r&r#r#r#r$Ú<module>s0    
 ÿ