U ÀÒ.eo+ã @sdZddlZddlmZmZddlmZddlmZ ddl m Z m Z m Z mZmZddlmZeršddlmZdd lmZmZmZdd lmZeeeefZe e¡Zz ddlZWnLe k rÈdZYn6e!k rüZ"ze #d ee"ƒ¡dZW5dZ"["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)ÚValues)ÚDictÚOptionalÚTuple)ÚAuthInfoú*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ÚpasswordZ get_passwordÚ ExceptionÚwarningÚstr)ÚurlrrZcredrÚexc©rú>/usr/lib/python3.8/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#rrrÚ__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ÚprefixrrrÚ_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 rrr-rr )r&Ú original_urlZ allow_netrcZ allow_keyringrÚnetlocZurl_user_passwordrrZ index_urlZ index_infoÚ_Zindex_url_user_passwordZ netrc_authZkr_authrrrÚ_get_new_credentialsns>ÿ        þ 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$Úgetr1ÚAssertionErrorÚformat)r&r.rr/r0rrrrrÚ_get_url_and_credentials s& þþüüûz-MultiDomainBasicAuth._get_url_and_credentialscCsH| |j¡\}}}||_|dk r6|dk r6t||ƒ|ƒ}| d|j¡|S)NÚresponse)r7rrÚ register_hookÚ handle_401)r&ÚreqrrrrrrÚ__call__Ès zMultiDomainBasicAuth.__call__cCsFtd|ƒ}|sdSt||ƒ}|r4|d|ddfStdƒ}||dfS)Nz User for %s: r2réFz Password: T)rr r)r&r/rZauthrrrrÚ_prompt_for_passwordÙs  z)MultiDomainBasicAuth._prompt_for_passwordcCstsdStdddgƒdkS)NFz#Save credentials to keyring [y/N]: ÚyÚn)rr)r&rrrÚ _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é‘r3r8)Ú status_coder"Ú urllib_parseZurlparserr>r/r%r$rAZcontentÚrawZ release_connrÚrequestr9Ú warn_on_401Úsave_credentialsZ connectionÚsendÚhistoryÚappend) r&ÚrespÚkwargsZparsedrrZsaver;Znew_resprrrr:és(     zMultiDomainBasicAuth.handle_401cKs|jdkrt d|jj¡dS)z6Response callback to warn about incorrect credentials.rBz)401 Error, Credentials not correct for %sN)rCrrrFr)r&rLrMrrrrGs  ÿ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 keyringizSaving credentials to keyringzFailed to save credentials) rr5r%rCrÚinfoZ set_passwordrZ exception)r&rLrMZcredsrrrrHs z%MultiDomainBasicAuth.save_credentials)TN)TT) Ú__name__Ú __module__Ú __qualname__r'r-r1r7r<r>rAr:rGrHrrrrr!Ks ÿ 2( -r!)&Ú__doc__ZloggingZpip._vendor.requests.authrrZpip._vendor.requests.utilsrZpip._vendor.six.moves.urllibrrDZpip._internal.utils.miscrrrr r Zpip._internal.utils.typingr Zoptparser Útypingr rrZ pip._internal.vcs.versioncontrolrrZ CredentialsZ getLoggerrOrrÚ ImportErrorrrrr r!rrrrÚs0        ÿ