summaryrefslogtreecommitdiff
path: root/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/exceptions.py
diff options
context:
space:
mode:
Diffstat (limited to 'venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/exceptions.py')
-rw-r--r--venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/exceptions.py249
1 files changed, 0 insertions, 249 deletions
diff --git a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/exceptions.py b/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/exceptions.py
deleted file mode 100644
index 28705c8..0000000
--- a/venv/lib/python3.7/site-packages/pip-10.0.1-py3.7.egg/pip/_internal/exceptions.py
+++ /dev/null
@@ -1,249 +0,0 @@
1"""Exceptions used throughout package"""
2from __future__ import absolute_import
3
4from itertools import chain, groupby, repeat
5
6from pip._vendor.six import iteritems
7
8
9class PipError(Exception):
10 """Base pip exception"""
11
12
13class ConfigurationError(PipError):
14 """General exception in configuration"""
15
16
17class InstallationError(PipError):
18 """General exception during installation"""
19
20
21class UninstallationError(PipError):
22 """General exception during uninstallation"""
23
24
25class DistributionNotFound(InstallationError):
26 """Raised when a distribution cannot be found to satisfy a requirement"""
27
28
29class RequirementsFileParseError(InstallationError):
30 """Raised when a general error occurs parsing a requirements file line."""
31
32
33class BestVersionAlreadyInstalled(PipError):
34 """Raised when the most up-to-date version of a package is already
35 installed."""
36
37
38class BadCommand(PipError):
39 """Raised when virtualenv or a command is not found"""
40
41
42class CommandError(PipError):
43 """Raised when there is an error in command-line arguments"""
44
45
46class PreviousBuildDirError(PipError):
47 """Raised when there's a previous conflicting build directory"""
48
49
50class InvalidWheelFilename(InstallationError):
51 """Invalid wheel filename."""
52
53
54class UnsupportedWheel(InstallationError):
55 """Unsupported wheel."""
56
57
58class HashErrors(InstallationError):
59 """Multiple HashError instances rolled into one for reporting"""
60
61 def __init__(self):
62 self.errors = []
63
64 def append(self, error):
65 self.errors.append(error)
66
67 def __str__(self):
68 lines = []
69 self.errors.sort(key=lambda e: e.order)
70 for cls, errors_of_cls in groupby(self.errors, lambda e: e.__class__):
71 lines.append(cls.head)
72 lines.extend(e.body() for e in errors_of_cls)
73 if lines:
74 return '\n'.join(lines)
75
76 def __nonzero__(self):
77 return bool(self.errors)
78
79 def __bool__(self):
80 return self.__nonzero__()
81
82
83class HashError(InstallationError):
84 """
85 A failure to verify a package against known-good hashes
86
87 :cvar order: An int sorting hash exception classes by difficulty of
88 recovery (lower being harder), so the user doesn't bother fretting
89 about unpinned packages when he has deeper issues, like VCS
90 dependencies, to deal with. Also keeps error reports in a
91 deterministic order.
92 :cvar head: A section heading for display above potentially many
93 exceptions of this kind
94 :ivar req: The InstallRequirement that triggered this error. This is
95 pasted on after the exception is instantiated, because it's not
96 typically available earlier.
97
98 """
99 req = None
100 head = ''
101
102 def body(self):
103 """Return a summary of me for display under the heading.
104
105 This default implementation simply prints a description of the
106 triggering requirement.
107
108 :param req: The InstallRequirement that provoked this error, with
109 populate_link() having already been called
110
111 """
112 return ' %s' % self._requirement_name()
113
114 def __str__(self):
115 return '%s\n%s' % (self.head, self.body())
116
117 def _requirement_name(self):
118 """Return a description of the requirement that triggered me.
119
120 This default implementation returns long description of the req, with
121 line numbers
122
123 """
124 return str(self.req) if self.req else 'unknown package'
125
126
127class VcsHashUnsupported(HashError):
128 """A hash was provided for a version-control-system-based requirement, but
129 we don't have a method for hashing those."""
130
131 order = 0
132 head = ("Can't verify hashes for these requirements because we don't "
133 "have a way to hash version control repositories:")
134
135
136class DirectoryUrlHashUnsupported(HashError):
137 """A hash was provided for a version-control-system-based requirement, but
138 we don't have a method for hashing those."""
139
140 order = 1
141 head = ("Can't verify hashes for these file:// requirements because they "
142 "point to directories:")
143
144
145class HashMissing(HashError):
146 """A hash was needed for a requirement but is absent."""
147
148 order = 2
149 head = ('Hashes are required in --require-hashes mode, but they are '
150 'missing from some requirements. Here is a list of those '
151 'requirements along with the hashes their downloaded archives '
152 'actually had. Add lines like these to your requirements files to '
153 'prevent tampering. (If you did not enable --require-hashes '
154 'manually, note that it turns on automatically when any package '
155 'has a hash.)')
156
157 def __init__(self, gotten_hash):
158 """
159 :param gotten_hash: The hash of the (possibly malicious) archive we
160 just downloaded
161 """
162 self.gotten_hash = gotten_hash
163
164 def body(self):
165 # Dodge circular import.
166 from pip._internal.utils.hashes import FAVORITE_HASH
167
168 package = None
169 if self.req:
170 # In the case of URL-based requirements, display the original URL
171 # seen in the requirements file rather than the package name,
172 # so the output can be directly copied into the requirements file.
173 package = (self.req.original_link if self.req.original_link
174 # In case someone feeds something downright stupid
175 # to InstallRequirement's constructor.
176 else getattr(self.req, 'req', None))
177 return ' %s --hash=%s:%s' % (package or 'unknown package',
178 FAVORITE_HASH,
179 self.gotten_hash)
180
181
182class HashUnpinned(HashError):
183 """A requirement had a hash specified but was not pinned to a specific
184 version."""
185
186 order = 3
187 head = ('In --require-hashes mode, all requirements must have their '
188 'versions pinned with ==. These do not:')
189
190
191class HashMismatch(HashError):
192 """
193 Distribution file hash values don't match.
194
195 :ivar package_name: The name of the package that triggered the hash
196 mismatch. Feel free to write to this after the exception is raise to
197 improve its error message.
198
199 """
200 order = 4
201 head = ('THESE PACKAGES DO NOT MATCH THE HASHES FROM THE REQUIREMENTS '
202 'FILE. If you have updated the package versions, please update '
203 'the hashes. Otherwise, examine the package contents carefully; '
204 'someone may have tampered with them.')
205
206 def __init__(self, allowed, gots):
207 """
208 :param allowed: A dict of algorithm names pointing to lists of allowed
209 hex digests
210 :param gots: A dict of algorithm names pointing to hashes we
211 actually got from the files under suspicion
212 """
213 self.allowed = allowed
214 self.gots = gots
215
216 def body(self):
217 return ' %s:\n%s' % (self._requirement_name(),
218 self._hash_comparison())
219
220 def _hash_comparison(self):
221 """
222 Return a comparison of actual and expected hash values.
223
224 Example::
225
226 Expected sha256 abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde
227 or 123451234512345123451234512345123451234512345
228 Got bcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdefbcdef
229
230 """
231 def hash_then_or(hash_name):
232 # For now, all the decent hashes have 6-char names, so we can get
233 # away with hard-coding space literals.
234 return chain([hash_name], repeat(' or'))
235
236 lines = []
237 for hash_name, expecteds in iteritems(self.allowed):
238 prefix = hash_then_or(hash_name)
239 lines.extend((' Expected %s %s' % (next(prefix), e))
240 for e in expecteds)
241 lines.append(' Got %s\n' %
242 self.gots[hash_name].hexdigest())
243 prefix = ' or'
244 return '\n'.join(lines)
245
246
247class UnsupportedPythonVersion(InstallationError):
248 """Unsupported python version according to Requires-Python package
249 metadata."""