a  ze}- @s*dZddlZddlmZmZmZmZmZddl m Z m Z ddl m Z mZddlmZddlmZddlmZmZmZmZmZdd lmZeeZeeeefZz ddlaWnLe ydaYn8e!yZ"z e#d ee"daWYdZ"["n dZ"["00eeeeeed d d Z$Gddde Z%dS)zNetwork Authentication Helpers Contains interface (MultiDomainBasicAuth) and associated glue code for providing credentials in the context of network requests. N)AnyDictListOptionalTuple)AuthBase HTTPBasicAuth)RequestResponse)get_netrc_auth) getLogger)ask ask_input ask_passwordremove_auth_from_urlsplit_auth_netloc_from_url)AuthInfo*Keyring is skipped due to an exception: %s)urlusernamereturnc Cs|rts dSz~z tj}Wnty*Yn40td||||}|durX|j|jfWSWdS|rtd|t||}|r||fWSWn8ty}z t dt |daWYd}~n d}~00dS)z3Return the tuple auth for a given url from keyring.Nz'Getting credentials from keyring for %sz$Getting password from keyring for %sr) keyringget_credentialAttributeErrorloggerdebugrpassword get_password Exceptionwarningstr)rrrcredrexcr#\/opt/bitninja-python-dojo/embedded/lib/python3.9/site-packages/pip/_internal/network/auth.pyget_keyring_auth(s0      r%c@seZdZd eeeeddddZeeedddZd!eeee d d d Z ee eeeeefd ddZ e e dddZee eeeeefdddZedddZeeedddZeeddddZeeddddZdS)"MultiDomainBasicAuthTN) prompting index_urlsrcCs||_||_i|_d|_dS)N)r'r( passwords_credentials_to_save)selfr'r(r#r#r$__init__JszMultiDomainBasicAuth.__init__)rrcCsB|r |jsdS|jD](}t|dd}||r|SqdS)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(rrstrip startswith)r+ruprefixr#r#r$_get_index_urlWs    z#MultiDomainBasicAuth._get_index_urlF) original_url allow_netrc allow_keyringrcCst|\}}}|\}}|dur6|dur6td||S||} | rft| } | rf| \} } } td| | r| ddur| \}}|dur|durtd|| S|rt|} | rtd|| S|rt| |pt||}|rtd||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)rrrr2r r%)r+r3r4r5rnetlocurl_user_passwordrr index_url index_info_index_url_user_password netrc_authkr_authr#r#r$_get_new_credentialsms>         z)MultiDomainBasicAuth._get_new_credentials)r3rcCst|\}}}||\}}|dur>|dur>|j|d\}}|dusN|durl|pTd}|p\d}||f|j|<|dur||dus|dur|dusJd||||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. N)NNz%Could not load credentials from url: )rr>r)get)r+r3rr6r:rrr#r#r$_get_url_and_credentialss& z-MultiDomainBasicAuth._get_url_and_credentials)reqrcCsH||j\}}}||_|dur6|dur6t|||}|d|j|S)Nresponse)rArr register_hook handle_401)r+rBrrrr#r#r$__call__s zMultiDomainBasicAuth.__call__)r6rcCsbtd|d}|sdSt||}|rP|ddurP|ddurP|d|ddfStd}||dfS) Nz User for z: )NNFrFz Password: T)rr%r)r+r6rauthrr#r#r$_prompt_for_passwords z)MultiDomainBasicAuth._prompt_for_password)rcCstsdStdddgdkS)NFz#Save credentials to keyring [y/N]: yn)rr )r+r#r#r$ _should_save_password_to_keyringsz5MultiDomainBasicAuth._should_save_password_to_keyring)respkwargsrc Ks|jdkr|S|js|Stj|j}|j|jddd\}}d}|sZ|sZ||j\}}}d|_ |dur|dur||f|j |j<|r| r|j||f|_ |j |j t|pd|pd|j}|d|j|j r|d|j|jj|fi|}|j||S)NFT)r4r5r?rC) status_coder'urllibparseurlparserr>rIr6r*r)rLcontentraw release_connrrequestrD warn_on_401save_credentials connectionsendhistoryappend) r+rMrNparsedrrsaverBnew_respr#r#r$rEs6     zMultiDomainBasicAuth.handle_401cKs|jdkrtd|jjdS)z6Response callback to warn about incorrect credentials.rOz)401 Error, Credentials not correct for %sN)rPrrrWr)r+rMrNr#r#r$rX's  z MultiDomainBasicAuth.warn_on_401cKsltdusJdtsdS|j}d|_|rh|jdkrhztdtj|WntyftdYn0dS)z1Response callback to save credentials on success.Nz'should never reach here without keyringizSaving credentials to keyringzFailed to save credentials)rr*rPrinfo set_passwordr exception)r+rMrNcredsr#r#r$rY/s  z%MultiDomainBasicAuth.save_credentials)TN)TF)__name__ __module__ __qualname__boolrrr r,r2rr>rrAr rFrIrLr rrErXrYr#r#r#r$r&Is2   9 ) 6r&)&__doc__ urllib.parserQtypingrrrrrZpip._vendor.requests.authrrZpip._vendor.requests.modelsr r Zpip._vendor.requests.utilsr pip._internal.utils.loggingr pip._internal.utils.miscr rrrr pip._internal.vcs.versioncontrolrrerr Credentialsr ImportErrorrr"rr%r&r#r#r#r$s,     !