← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-nascentuploadfile-checksum into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-nascentuploadfile-checksum into launchpad:master.

Commit message:
Fix NascentUploadFile checksumming for Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/397104

We need to open the file in binary mode.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-nascentuploadfile-checksum into launchpad:master.
diff --git a/lib/lp/archiveuploader/nascentuploadfile.py b/lib/lp/archiveuploader/nascentuploadfile.py
index 9e48cc3..dc5a8ed 100644
--- a/lib/lp/archiveuploader/nascentuploadfile.py
+++ b/lib/lp/archiveuploader/nascentuploadfile.py
@@ -217,13 +217,12 @@ class NascentUploadFile:
         # Read in the file and compute its md5 and sha1 checksums and remember
         # the size of the file as read-in.
         digesters = dict((n, hashlib.new(n)) for n in self.checksums.keys())
-        ckfile = open(self.filepath, "r")
-        size = 0
-        for chunk in filechunks(ckfile):
-            for digester in six.itervalues(digesters):
-                digester.update(chunk)
-            size += len(chunk)
-        ckfile.close()
+        with open(self.filepath, "rb") as ckfile:
+            size = 0
+            for chunk in filechunks(ckfile):
+                for digester in six.itervalues(digesters):
+                    digester.update(chunk)
+                size += len(chunk)
 
         # Check the size and checksum match what we were told in __init__
         for n in sorted(self.checksums.keys()):