3 Re-@s(dZddlZddlmZmZddlmZddlmZ ddl m Z m Z m Z mZmZddlmZerddlmZmZmZmZmZdd lmZdd lmZmZeeeefZeje Z!y ddl"a"WnNe#k rda"Yn8e$k r Z%ze!j&d ee%da"WYddZ%[%XnXd d Z'GdddeZ(dS)zNetwork 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_passwordremove_auth_from_urlsplit_auth_netloc_from_url)MYPY_CHECK_RUNNING)DictOptionalTupleListAny)AuthInfo)ResponseRequestz*Keyring is skipped due to an exception: %scCs| s t rdSyzy tj}Wntk r0Yn0Xtjd||||}|dk r\|j|jfSdS|rtjd|tj||}|r||fSWn6tk r}ztj dt |daWYdd}~XnXdS)z3Return the tuple auth for a given url from keyring.Nz'Getting credentials from keyring for %sz$Getting password from keyring for %sz*Keyring is skipped due to an exception: %s) keyringget_credentialAttributeErrorloggerdebugusernamepassword get_password Exceptionwarningstr)urlrrcredrexcr"/builddir/build/BUILDROOT/alt-python36-pip-20.2.4-5.el9.x86_64/opt/alt/python36/lib/python3.6/site-packages/pip/_internal/network/auth.pyget_keyring_auth,s,         r$c@s`eZdZdddZddZdddZd d Zd d Zd dZddZ ddZ ddZ ddZ dS)MultiDomainBasicAuthTNcCs||_||_i|_d|_dS)N) prompting index_urls passwords_credentials_to_save)selfr&r'r"r"r#__init__OszMultiDomainBasicAuth.__init__cCsF| s|j rdSx.|jD]$}t|jdd}|j|r|SqWdS)aReturn 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*ruprefixr"r"r#_get_index_url[s  z#MultiDomainBasicAuth._get_index_urlcCst|\}}}|\}}|dk r6|dk r6tjd||S|j|} | rft| } | rf| \} } } tjd| | r| ddk r| \}}|dk r|dk rtjd|| S|rt|} | rtjd|| S|rt| |pt||}|rtjd||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 rrr1rr$)r* original_url allow_netrc allow_keyringrnetlocurl_user_passwordrr index_url index_info_index_url_user_password netrc_authkr_authr"r"r#_get_new_credentialsrs:          z)MultiDomainBasicAuth._get_new_credentialscCst|\}}}|jj|d\}}|dkr>|dkr>|j|\}}|dk sN|dk rl|pTd}|p\d}||f|j|<|dk r||dk s|dkr|dkstdj||||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. Nz'Could not load credentials from url: {})NN)r r(getr=AssertionErrorformat)r*r2rr5r9rrr"r"r#_get_url_and_credentialss  z-MultiDomainBasicAuth._get_url_and_credentialscCsH|j|j\}}}||_|dk r6|dk r6t|||}|jd|j|S)Nresponse)rBrr register_hook handle_401)r*reqrrrr"r"r#__call__s zMultiDomainBasicAuth.__call__cCs`tdj|}|sdSt||}|rN|ddk rN|ddk rN|d|ddfStd}||dfS)Nz User for {}: Frz Password: T)NNF)rrAr$r)r*r5rauthrr"r"r#_prompt_for_passwords z)MultiDomainBasicAuth._prompt_for_passwordcCstsdStdddgdkS)NFz#Save credentials to keyring [y/N]: yn)rr)r*r"r"r# _should_save_password_to_keyringsz5MultiDomainBasicAuth._should_save_password_to_keyringc Ks|jdkr|S|js|Stj|j}|j|j\}}}d|_|dk rv|dk rv||f|j|j<|rv|j rv|j||f|_|j |j j t |pd|pd|j}|jd|j|jr|jd|j|jj|f|}|jj||S)Nir>rC) status_coder& urllib_parseurlparserrJr5r)r(rMcontentraw release_connrrequestrD warn_on_401save_credentials connectionsendhistoryappend) r*respkwargsparsedrrsaverFnew_respr"r"r#rEs(     zMultiDomainBasicAuth.handle_401cKs|jdkrtjd|jjdS)z6Response callback to warn about incorrect credentials.iz)401 Error, Credentials not correct for %sN)rNrrrTr)r*r[r\r"r"r#rU s z MultiDomainBasicAuth.warn_on_401c Ksntdk stdtsdS|j}d|_|rj|jdkrjytjdtj|Wntk rhtjdYnXdS)z1Response callback to save credentials on success.Nz'should never reach here without keyringizSaving credentials to keyringzFailed to save credentials) rr@r)rNrinfo set_passwordr exception)r*r[r\credsr"r"r#rV(s z%MultiDomainBasicAuth.save_credentials)TN)TT) __name__ __module__ __qualname__r+r1r=rBrGrJrMrErUrVr"r"r"r#r%Ms  2) .r%))__doc__loggingZpip._vendor.requests.authrrZpip._vendor.requests.utilsrZpip._vendor.six.moves.urllibrrOpip._internal.utils.miscrrrr r pip._internal.utils.typingr typingr r rrr pip._internal.vcs.versioncontrolrZpip._vendor.requests.modelsrrrZ Credentials getLoggerrdrr ImportErrorrr!rr$r%r"r"r"r#s,       !