[Python-checkins] Fix EncodingWarning in freeze_modules. (GH-28591)

methane webhook-mailer at python.org
Wed Sep 29 23:36:23 EDT 2021


https://github.com/python/cpython/commit/a1437170039dc2c07e6040d3a8ba8d91434b730d
commit: a1437170039dc2c07e6040d3a8ba8d91434b730d
branch: main
author: Inada Naoki <songofacandy at gmail.com>
committer: methane <songofacandy at gmail.com>
date: 2021-09-30T12:36:16+09:00
summary:

Fix EncodingWarning in freeze_modules. (GH-28591)

files:
M Tools/scripts/freeze_modules.py

diff --git a/Tools/scripts/freeze_modules.py b/Tools/scripts/freeze_modules.py
index f7273915b911e..ea96253df3e49 100644
--- a/Tools/scripts/freeze_modules.py
+++ b/Tools/scripts/freeze_modules.py
@@ -329,10 +329,10 @@ def _iter_sources(modules):
 # generic helpers
 
 def _get_checksum(filename):
-    with open(filename) as infile:
-        text = infile.read()
+    with open(filename, "rb") as infile:
+        contents = infile.read()
     m = hashlib.sha256()
-    m.update(text.encode('utf8'))
+    m.update(contents)
     return m.hexdigest()
 
 
@@ -489,7 +489,7 @@ def regen_manifest(modules):
         modlines.append(' '.join(row).rstrip())
 
     print(f'# Updating {os.path.relpath(MANIFEST)}')
-    with open(MANIFEST, 'w') as outfile:
+    with open(MANIFEST, 'w', encoding="utf-8") as outfile:
         lines = (l + '\n' for l in modlines)
         outfile.writelines(lines)
 



More information about the Python-checkins mailing list