3 ig1@s4dZddlZddlmZmZmZddlmZmZm Z m Z m Z ddl m Z ddlmZmZerddlmZddlmZdd lmZGd d d eZGd d d eZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZGdddeZ GdddeZ!GdddeZ"Gd d!d!eZ#Gd"d#d#eZ$Gd$d%d%eZ%Gd&d'd'eZ&Gd(d)d)eZ'Gd*d+d+eZ(Gd,d-d-eZ)Gd.d/d/eZ*Gd0d1d1eZ+Gd2d3d3e+Z,Gd4d5d5e+Z-Gd6d7d7e+Z.Gd8d9d9e+Z/Gd:d;d;e+Z0Gdd?d?eZ2dS)@z"Exceptions used throughout packageN)chaingroupbyrepeat) TYPE_CHECKINGDictListOptionalUnion) Distribution)RequestResponse)_Hash)BaseDistribution)InstallRequirementc@seZdZdZdS)PipErrorzBase pip exceptionN)__name__ __module__ __qualname____doc__rr7/tmp/pip-build-88gy_88q/pip/pip/_internal/exceptions.pyrsrc@seZdZdZdS)ConfigurationErrorz"General exception in configurationN)rrrrrrrrrsrc@seZdZdZdS)InstallationErrorz%General exception during installationN)rrrrrrrrrsrc@seZdZdZdS)UninstallationErrorz'General exception during uninstallationN)rrrrrrrrrsrc@s8eZdZdZeedfeddddZeddd ZdS) NoneMetadataErrora Raised when accessing "METADATA" or "PKG-INFO" metadata for a pip._vendor.pkg_resources.Distribution object and `dist.has_metadata('METADATA')` returns True but `dist.get_metadata('METADATA')` returns None (and similarly for "PKG-INFO"). rN)dist metadata_namereturncCs||_||_dS)z :param dist: A Distribution object. :param metadata_name: The name of the metadata being accessed (can be "METADATA" or "PKG-INFO"). N)rr)selfrrrrr__init__*s zNoneMetadataError.__init__)rcCsdj|j|jS)Nz+None {} metadata found for distribution: {})formatrr)rrrr__str__7szNoneMetadataError.__str__) rrrrr r strrr!rrrrr!s   rc@seZdZdZedddZdS)UserInstallationInvalidzBA --user install is requested on an environment without user site.)rcCsdS)Nz$User base directory is not specifiedr)rrrrr!CszUserInstallationInvalid.__str__N)rrrrr"r!rrrrr#@sr#c@seZdZedddZdS)InvalidSchemeCombination)rcCs6djdd|jddD}d|d|jd dS) Nz, css|]}t|VqdS)N)r").0arrr Isz3InvalidSchemeCombination.__str__..z Cannot set z and z togetherr))joinargs)rZbeforerrrr!Hsz InvalidSchemeCombination.__str__N)rrrr"r!rrrrr$Gsr$c@seZdZdZdS)DistributionNotFoundzCRaised when a distribution cannot be found to satisfy a requirementN)rrrrrrrrr,Msr,c@seZdZdZdS)RequirementsFileParseErrorzDRaised when a general error occurs parsing a requirements file line.N)rrrrrrrrr-Qsr-c@seZdZdZdS)BestVersionAlreadyInstalledzNRaised when the most up-to-date version of a package is already installed.N)rrrrrrrrr.Usr.c@seZdZdZdS) BadCommandz0Raised when virtualenv or a command is not foundN)rrrrrrrrr/Zsr/c@seZdZdZdS) CommandErrorz7Raised when there is an error in command-line argumentsN)rrrrrrrrr0^sr0c@seZdZdZdS)PreviousBuildDirErrorz:Raised when there's a previous conflicting build directoryN)rrrrrrrrr1bsr1cs<eZdZdZd eeeddfdd ZedddZZ S) NetworkConnectionErrorzHTTP connection errorN) error_msgresponserequestrcsL||_||_||_|jdk r8|j r8t|dr8|jj|_tj|||dS)zc Initialize NetworkConnectionError with `request` and `response` objects. Nr5)r4r5r3hasattrsuperr)rr3r4r5) __class__rrris   zNetworkConnectionError.__init__)rcCs t|jS)N)r"r3)rrrrr!{szNetworkConnectionError.__str__)NN) rrrrr"r r rr! __classcell__rr)r8rr2fsr2c@seZdZdZdS)InvalidWheelFilenamezInvalid wheel filename.N)rrrrrrrrr:sr:c@seZdZdZdS)UnsupportedWheelzUnsupported wheel.N)rrrrrrrrr;sr;c@s4eZdZdZdeeeddddZeddd ZdS) MetadataInconsistentzBuilt 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)ireqfieldf_valm_valrcCs||_||_||_||_dS)N)r=r>r?r@)rr=r>r?r@rrrrszMetadataInconsistent.__init__)rcCsd}|j|j|j|j|jS)NzJRequested {} has inconsistent {}: filename has {!r}, but metadata has {!r})r r=r>r?r@)rtemplaterrrr!szMetadataInconsistent.__str__)rrrrr"rr!rrrrr<sr<c@s0eZdZdZeeddddZedddZdS) InstallationSubprocessErrorz-A subprocess call failed during installation.N) returncode descriptionrcCs||_||_dS)N)rCrD)rrCrDrrrrsz$InstallationSubprocessError.__init__)rcCsdj|j|jS)NzSCommand errored out with exit status {}: {} Check the logs for full command output.)r rCrD)rrrrr!sz#InstallationSubprocessError.__str__)rrrrintr"rr!rrrrrBsrBc@sJeZdZdZddddZddddd Zedd d Zedd d Z dS) HashErrorsz:Multiple HashError instances rolled into one for reportingN)rcCs g|_dS)N)errors)rrrrrszHashErrors.__init__ HashError)errorrcCs|jj|dS)N)rGappend)rrIrrrrJszHashErrors.appendcCsfg}|jjdddxsz$HashErrors.__str__..)keycSs|jS)N)r8)rLrrrrMscss|]}|jVqdS)N)body)r%rLrrrr'sz%HashErrors.__str__.. )rGsortrrJheadextendr*)rlinescls errors_of_clsrrrr!s  zHashErrors.__str__cCs t|jS)N)boolrG)rrrr__bool__szHashErrors.__bool__) rrrrrrJr"r!rXrYrrrrrFs  rFc@sTeZdZUdZdZeddZd Zee dddZ e dd d Z e dd d Z dS)rHa 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. NrrQr()rcCsd|jS)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_name)rrrrrOs zHashError.bodycCs|jd|jS)NrP)rSrO)rrrrr!szHashError.__str__cCs|jrt|jSdS)zReturn a description of the requirement that triggered me. This default implementation returns long description of the req, with line numbers zunknown package)reqr")rrrrrZszHashError._requirement_namer)) rrrrr[rrSrKrEr"rOr!rZrrrrrHs   rHc@seZdZdZdZdZdS)VcsHashUnsupportedzuA 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)rrrrrKrSrrrrr\sr\c@seZdZdZdZdZdS)DirectoryUrlHashUnsupportedzuA hash was provided for a version-control-system-based requirement, but we don't have a method for hashing those.r(zUCan't verify hashes for these file:// requirements because they point to directories:N)rrrrrKrSrrrrr]sr]c@s6eZdZdZdZdZeddddZedd 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)r`)rr`rrrrszHashMissing.__init__)rcCsHddlm}d}|jr4|jjr&|jjn t|jdd}dj|p>d||jS)Nr) FAVORITE_HASHr[z {} --hash={}:{}zunknown package)Zpip._internal.utils.hashesrar[ original_linkgetattrr r`)rrapackagerrrrOs zHashMissing.body) rrrrrKrSr"rrOrrrrr^s  r^c@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:N)rrrrrKrSrrrrre2srec@sZeZdZdZdZdZeeeefeedfddddZ 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. zTHESE 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)allowedgotsrcCs||_||_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)rirj)rrirjrrrrOszHashMismatch.__init__)rcCsdj|j|jS)Nz {}: {})r rZ_hash_comparison)rrrrrOYszHashMismatch.bodycsptdddd}g}xP|jjD]B\}}|||jfdd|D|jdj|j|jq Wdj|S) aE Return a comparison of actual and expected hash values. Example:: Expected sha256 abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde or 123451234512345123451234512345123451234512345 Got bcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdef z chain[str]) hash_namercSst|gtdS)Nz or)rr)rlrrr hash_then_orhsz3HashMismatch._hash_comparison..hash_then_orc3s|]}djt|VqdS)z Expected {} {}N)r next)r%rL)prefixrrr'qsz0HashMismatch._hash_comparison..z Got {} rP) r"riitemsrTrJr rj hexdigestr*)rrmrUrl expectedsr)rorrk\s zHashMismatch._hash_comparison) rrrrrKrSrr"rrrOrkrrrrrg=s & rgc@seZdZdZdS)UnsupportedPythonVersionzMUnsupported python version according to Requires-Python package metadata.N)rrrrrrrrrsysrscsFeZdZdZd eeeeejddfdd Zeddd Z Z S) !ConfigurationFileCouldNotBeLoadedz8When there are errors while loading a configuration filecould not be loadedN)reasonfnamerIrcs"tj|||_||_||_dS)N)r7rrvrwrI)rrvrwrI)r8rrrs z*ConfigurationFileCouldNotBeLoaded.__init__)rcCsF|jdk rd|jd}n|jdk s(td|jd}d|j|S)Nz in .z. rPzConfiguration file )rwrIAssertionErrorrv)rZ message_partrrrr!s  z)ConfigurationFileCouldNotBeLoaded.__str__)ruNN) rrrrr"r configparserErrorrr!r9rr)r8rrt~s rt)3rrz itertoolsrrrZtypingrrrrr Zpip._vendor.pkg_resourcesr Zpip._vendor.requests.modelsr r hashlibr Zpip._internal.metadatarZpip._internal.req.req_installr Exceptionrrrrrr#r$r,r-r.r/r0r1r2r:r;r<rBrFrHr\r]r^rergrsrtrrrrsH    .  * <