1
1
Fork 0
mirror of https://github.com/pypa/pip synced 2023-12-13 21:30:23 +01:00

Rename "goods" to "allowed" for clarity.

Renaming "gots" didn't go well. I think the current naming is the most concise way to put it. If we rename it to "got", then the loop iterator can't be called "got", and the simple relationship between the iterator and collection names is lost. "Actual" and "actuals" are the other names that occurred to me, but they look so much like "allowed" that the code becomes harder to read.
This commit is contained in:
Erik Rose 2015-10-11 09:00:01 -04:00
parent 304c90aa46
commit 05b7ef9467
2 changed files with 10 additions and 10 deletions

View file

@ -198,14 +198,14 @@ class HashMismatch(HashError):
'the hashes. Otherwise, examine the package contents carefully; '
'someone may have tampered with them.')
def __init__(self, goods, gots):
def __init__(self, allowed, gots):
"""
:param goods: A dict of algorithm names pointing to lists of allowed
: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
"""
self.goods = goods
self.allowed = allowed
self.gots = gots
def body(self):
@ -229,7 +229,7 @@ class HashMismatch(HashError):
return chain([hash_name], repeat(' or'))
lines = []
for hash_name, expecteds in iteritems(self.goods):
for hash_name, expecteds in iteritems(self.allowed):
prefix = hash_then_or(hash_name)
lines.extend((' Expected %s %s' % (next(prefix), e))
for e in expecteds)

View file

@ -17,7 +17,7 @@ class Hashes(object):
:param hashes: A dict of algorithm names pointing to lists of allowed
hex digests
"""
self._goods = {} if hashes is None else hashes
self._allowed = {} if hashes is None else hashes
def check_against_chunks(self, chunks):
"""Check good hashes against ones built from iterable of chunks of
@ -27,7 +27,7 @@ class Hashes(object):
"""
gots = {}
for hash_name in iterkeys(self._goods):
for hash_name in iterkeys(self._allowed):
try:
gots[hash_name] = hashlib.new(hash_name)
except (ValueError, TypeError):
@ -38,12 +38,12 @@ class Hashes(object):
hash.update(chunk)
for hash_name, got in iteritems(gots):
if got.hexdigest() in self._goods[hash_name]:
if got.hexdigest() in self._allowed[hash_name]:
return
self._raise(gots)
def _raise(self, gots):
raise HashMismatch(self._goods, gots)
raise HashMismatch(self._allowed, gots)
def check_against_file(self, file):
"""Check good hashes against a file-like object
@ -65,7 +65,7 @@ class Hashes(object):
def __nonzero__(self):
"""Return whether I know any known-good hashes."""
return bool(self._goods)
return bool(self._allowed)
def __bool__(self):
return self.__nonzero__()
@ -74,7 +74,7 @@ class Hashes(object):
class MissingHashes(Hashes):
"""A workalike for Hashes used when we're missing a hash for a requirement
It computes the "gotten" hash of the requirement and raises a HashMissing
It computes the actual hash of the requirement and raises a HashMissing
exception showing it to the user.
"""