a [›ýfÚ1ã@s4dZddlZddlmZmZmZddlmZmZm Z m Z m Z ddl m Z ddlmZmZer€ddlmZddlmZdd lmZGd d „d eƒZGd d „d eƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZ Gdd„deƒZ!Gdd„deƒZ"Gd d!„d!eƒZ#Gd"d#„d#eƒZ$Gd$d%„d%eƒZ%Gd&d'„d'eƒZ&Gd(d)„d)eƒZ'Gd*d+„d+eƒZ(Gd,d-„d-eƒZ)Gd.d/„d/eƒZ*Gd0d1„d1eƒZ+Gd2d3„d3e+ƒZ,Gd4d5„d5e+ƒZ-Gd6d7„d7e+ƒZ.Gd8d9„d9e+ƒZ/Gd:d;„d;e+ƒZ0Gdd?„d?eƒZ2dS)@z"Exceptions used throughout packageéN)ÚchainÚgroupbyÚrepeat)Ú TYPE_CHECKINGÚDictÚListÚOptionalÚUnion)Ú Distribution)ÚRequestÚResponse)Ú_Hash)ÚBaseDistribution)ÚInstallRequirementc@seZdZdZdS)ÚPipErrorzBase pip exceptionN©Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrúIóz3InvalidSchemeCombination.__str__..éÿÿÿÿz Cannot set z and z together)ÚjoinÚargs)rÚbeforerrrr$Hsz InvalidSchemeCombination.__str__N)rrrr%r$rrrrr'Gsr'c@seZdZdZdS)ÚDistributionNotFoundzCRaised when a distribution cannot be found to satisfy a requirementNrrrrrr1Msr1c@seZdZdZdS)ÚRequirementsFileParseErrorzDRaised when a general error occurs parsing a requirements file line.Nrrrrrr2Qsr2c@seZdZdZdS)ÚBestVersionAlreadyInstalledzNRaised when the most up-to-date version of a package is already installed.Nrrrrrr3Usr3c@seZdZdZdS)Ú BadCommandz0Raised when virtualenv or a command is not foundNrrrrrr4Zsr4c@seZdZdZdS)Ú CommandErrorz7Raised when there is an error in command-line argumentsNrrrrrr5^sr5c@seZdZdZdS)ÚPreviousBuildDirErrorz:Raised when there's a previous conflicting build directoryNrrrrrr6bsr6cs<eZdZdZd eeeddœ‡fdd„ Zedœdd„Z‡Z S) ÚNetworkConnectionErrorzHTTP connection errorN)Ú error_msgÚresponseÚrequestrcsJ||_||_||_|jdur6|js6t|dƒr6|jj|_tƒ |||¡dS)zc Initialize NetworkConnectionError with `request` and `response` objects. Nr:)r9r:r8ÚhasattrÚsuperr )rr8r9r:©Ú __class__rrr isÿþý zNetworkConnectionError.__init__r!cCs t|jƒSr()r%r8r#rrrr${szNetworkConnectionError.__str__)NN) rrrrr%r r r r$Ú __classcell__rrr=rr7fsÿþr7c@seZdZdZdS)ÚInvalidWheelFilenamezInvalid wheel filename.Nrrrrrr@sr@c@seZdZdZdS)ÚUnsupportedWheelzUnsupported wheel.NrrrrrrAƒsrAc@s4eZdZdZdeeeddœdd„Zedœdd „ZdS) ÚMetadataInconsistentzøBuilt metadata contains inconsistent information. This is raised when the metadata contains values (e.g. name and version) that do not match the information previously obtained from sdist filename or user-supplied ``#egg=`` value. rN)ÚireqÚfieldÚf_valÚm_valrcCs||_||_||_||_dSr()rCrDrErF)rrCrDrErFrrrr szMetadataInconsistent.__init__r!cCsd}| |j|j|j|j¡S)NzJRequested {} has inconsistent {}: filename has {!r}, but metadata has {!r})r"rCrDrErF)rÚtemplaterrrr$—sÿzMetadataInconsistent.__str__)rrrrr%r r$rrrrrB‡s þ rBc@s0eZdZdZeeddœdd„Zedœdd„ZdS) ÚInstallationSubprocessErrorz-A subprocess call failed during installation.N)Ú returncodeÚ descriptionrcCs||_||_dSr()rIrJ)rrIrJrrrr ¢sz$InstallationSubprocessError.__init__r!cCsd |j|j¡S)NzSCommand errored out with exit status {}: {} Check the logs for full command output.)r"rIrJr#rrrr$¦sÿýz#InstallationSubprocessError.__str__)rrrrÚintr%r r$rrrrrHŸsrHc@sJeZdZdZddœdd„Zdddœdd „Zedœd d „Zedœd d „Z dS)Ú HashErrorsz:Multiple HashError instances rolled into one for reportingNr!cCs g|_dSr()Úerrorsr#rrrr °szHashErrors.__init__Ú HashError)ÚerrorrcCs|j |¡dSr()rMÚappend)rrOrrrrP³szHashErrors.appendcCsbg}|jjdd„dt|jdd„ƒD](\}}| |j¡| dd„|Dƒ¡q&|r^d |¡SdS) NcSs|jSr()Úorder©ÚerrrÚ¸r,z$HashErrors.__str__..)ÚkeycSs|jSr(r=rRrrrrT¹r,css|]}| ¡VqdSr()Úbody©r)rSrrrr+»r,z%HashErrors.__str__..Ú Ú)rMÚsortrrPÚheadÚextendr.)rÚlinesÚclsZ errors_of_clsrrrr$¶s  zHashErrors.__str__cCs t|jƒSr()ÚboolrMr#rrrÚ__bool__ÀszHashErrors.__bool__) rrrrr rPr%r$r_r`rrrrrL­s  rLc@s\eZdZUdZdZeded<dZdZe ed<e dœd d „Z e dœd d „Z e dœd d„Z dS)rNa” A failure to verify a package against known-good hashes :cvar order: An int sorting hash exception classes by difficulty of recovery (lower being harder), so the user doesn't bother fretting about unpinned packages when he has deeper issues, like VCS dependencies, to deal with. Also keeps error reports in a deterministic order. :cvar head: A section heading for display above potentially many exceptions of this kind :ivar req: The InstallRequirement that triggered this error. This is pasted on after the exception is instantiated, because it's not typically available earlier. NrÚreqrYr-rQr!cCsd| ¡›S)a=Return a summary of me for display under the heading. This default implementation simply prints a description of the triggering requirement. :param req: The InstallRequirement that provoked this error, with its link already populated by the resolver's _populate_link(). z )Ú_requirement_namer#rrrrVÙs zHashError.bodycCs|j›d| ¡›S)NrX)r[rVr#rrrr$åszHashError.__str__cCs|jrt|jƒSdS)z¨Return a description of the requirement that triggered me. This default implementation returns long description of the req, with line numbers úunknown package)rar%r#rrrrbèszHashError._requirement_name)rrrrrarÚ__annotations__r[rQrKr%rVr$rbrrrrrNÄs   rNc@seZdZdZdZdZdS)ÚVcsHashUnsupportedúuA hash was provided for a version-control-system-based requirement, but we don't have a method for hashing those.rzlCan't verify hashes for these requirements because we don't have a way to hash version control repositories:N©rrrrrQr[rrrrreòsÿrec@seZdZdZdZdZdS)ÚDirectoryUrlHashUnsupportedrfézUCan't verify hashes for these file:// requirements because they point to directories:Nrgrrrrrhýsÿrhc@s6eZdZdZdZdZeddœdd„Zedœd d „ZdS) Ú HashMissingz2A hash was needed for a requirement but is absent.éawHashes are required in --require-hashes mode, but they are missing from some requirements. Here is a list of those requirements along with the hashes their downloaded archives actually had. Add lines like these to your requirements files to prevent tampering. (If you did not enable --require-hashes manually, note that it turns on automatically when any package has a hash.)N)Ú gotten_hashrcCs ||_dS)zq :param gotten_hash: The hash of the (possibly malicious) archive we just downloaded N)rl)rrlrrrr szHashMissing.__init__r!cCsHddlm}d}|jr4|jjr&|jjn t|jddƒ}d |p>d||j¡S)Nr)Ú FAVORITE_HASHraz {} --hash={}:{}rc)Zpip._internal.utils.hashesrmraZ original_linkÚgetattrr"rl)rrmÚpackagerrrrVs ÿ  û ÿzHashMissing.body) rrrrrQr[r%r rVrrrrrjs ÿ rjc@seZdZdZdZdZdS)Ú HashUnpinnedzPA requirement had a hash specified but was not pinned to a specific version.ézaIn --require-hashes mode, all requirements must have their versions pinned with ==. These do not:Nrgrrrrrp2sÿrpc@sZeZdZdZdZdZeeeefeedfddœdd„Z ed œd d „Z ed œd d „Z dS)Ú HashMismatchzî Distribution file hash values don't match. :ivar package_name: The name of the package that triggered the hash mismatch. Feel free to write to this after the exception is raise to improve its error message. ézÞTHESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS FILE. If you have updated the package versions, please update the hashes. Otherwise, examine the package contents carefully; someone may have tampered with them.r N)ÚallowedÚgotsrcCs||_||_dS)zí :param allowed: A dict of algorithm names pointing to lists of allowed hex digests :param gots: A dict of algorithm names pointing to hashes we actually got from the files under suspicion N)rtru)rrtrurrrr OszHashMismatch.__init__r!cCsd | ¡| ¡¡S)Nz {}: {})r"rbÚ_hash_comparisonr#rrrrVYszHashMismatch.bodycsltddœdd„}g}|j ¡D]B\}}||ƒ‰| ‡fdd„|Dƒ¡| d |j| ¡¡¡qd |¡S) aE Return a comparison of actual and expected hash values. Example:: Expected sha256 abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde or 123451234512345123451234512345123451234512345 Got bcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdef z chain[str])Ú hash_namercSst|gtdƒƒS)Nz or)rr)rwrrrÚ hash_then_orhsz3HashMismatch._hash_comparison..hash_then_orc3s|]}d tˆƒ|¡VqdS)z Expected {} {}N)r"ÚnextrW©Úprefixrrr+psz0HashMismatch._hash_comparison..z Got {} rX) r%rtÚitemsr\rPr"ruZ hexdigestr.)rrxr]rwZ expectedsrrzrrv\s ÿÿzHashMismatch._hash_comparison) rrrrrQr[rr%rr rVrvrrrrrr=s ÿ& rrc@seZdZdZdS)ÚUnsupportedPythonVersionzMUnsupported python version according to Requires-Python package metadata.Nrrrrrr}ysr}csFeZdZdZd eeeeejddœ‡fdd„ Zedœdd „Z ‡Z S) Ú!ConfigurationFileCouldNotBeLoadedz8When there are errors while loading a configuration fileúcould not be loadedN)ÚreasonÚfnamerOrcs"tƒ |¡||_||_||_dSr()r<r r€rrO)rr€rrOr=rrr s z*ConfigurationFileCouldNotBeLoaded.__init__r!cCsF|jdurd|j›d}n|jdus(J‚d|j›d}d|j›|›S)Nz in Ú.z. rXzConfiguration file )rrOr€)rZ message_partrrrr$Œs  z)ConfigurationFileCouldNotBeLoaded.__str__)rNN) rrrrr%rÚ configparserÚErrorr r$r?rrr=rr~~süû r~)3rrƒÚ itertoolsrrrÚtypingrrrrr Zpip._vendor.pkg_resourcesr Zpip._vendor.requests.modelsr r Zhashlibr Zpip._internal.metadatarZpip._internal.req.req_installrÚ Exceptionrrrrrr&r'r1r2r3r4r5r6r7r@rArBrHrLrNrerhrjrprrr}r~rrrrÚsH    .  * <