mirror of
https://github.com/python/cpython.git
synced 2025-11-15 00:00:00 +00:00
packaging: don't use locale encoding to compute MD5 checksums
Open the file in binary mode or use UTF-8 encoding.
This commit is contained in:
parent
cd0f7bfd32
commit
35de5ac44d
3 changed files with 7 additions and 7 deletions
|
|
@ -133,9 +133,9 @@ class install_distinfo(Command):
|
||||||
writer.writerow((fpath, '', ''))
|
writer.writerow((fpath, '', ''))
|
||||||
else:
|
else:
|
||||||
size = os.path.getsize(fpath)
|
size = os.path.getsize(fpath)
|
||||||
with open(fpath, 'r') as fp:
|
with open(fpath, 'rb') as fp:
|
||||||
hash = hashlib.md5()
|
hash = hashlib.md5()
|
||||||
hash.update(fp.read().encode())
|
hash.update(fp.read())
|
||||||
md5sum = hash.hexdigest()
|
md5sum = hash.hexdigest()
|
||||||
writer.writerow((fpath, md5sum, size))
|
writer.writerow((fpath, md5sum, size))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -400,10 +400,10 @@ class MainProgram:
|
||||||
self.data['description']).lower().encode())
|
self.data['description']).lower().encode())
|
||||||
ref = ref.digest()
|
ref = ref.digest()
|
||||||
for readme in glob.glob('README*'):
|
for readme in glob.glob('README*'):
|
||||||
with open(readme) as fp:
|
with open(readme, encoding='utf-8') as fp:
|
||||||
contents = fp.read()
|
contents = fp.read()
|
||||||
val = md5(re.sub('\s', '',
|
contents = re.sub('\s', '', contents.lower()).encode()
|
||||||
contents.lower()).encode()).digest()
|
val = md5(contents).digest()
|
||||||
if val == ref:
|
if val == ref:
|
||||||
del data['description']
|
del data['description']
|
||||||
data['description-file'] = readme
|
data['description-file'] = readme
|
||||||
|
|
|
||||||
|
|
@ -168,8 +168,8 @@ class InstallDistinfoTestCase(support.TempdirManager,
|
||||||
else:
|
else:
|
||||||
size = os.path.getsize(f)
|
size = os.path.getsize(f)
|
||||||
md5 = hashlib.md5()
|
md5 = hashlib.md5()
|
||||||
with open(f) as fp:
|
with open(f, 'rb') as fp:
|
||||||
md5.update(fp.read().encode())
|
md5.update(fp.read())
|
||||||
hash = md5.hexdigest()
|
hash = md5.hexdigest()
|
||||||
expected.append([f, hash, str(size)])
|
expected.append([f, hash, str(size)])
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue