← Back to team overview

launchpad-reviewers team mailing list archive

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

 

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

Commit message:
Fix various ResourceWarnings from Python 3

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/398903
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-resourcewarnings into launchpad:master.
diff --git a/lib/lp/archiveuploader/nascentuploadfile.py b/lib/lp/archiveuploader/nascentuploadfile.py
index 7183c9a..c08759a 100644
--- a/lib/lp/archiveuploader/nascentuploadfile.py
+++ b/lib/lp/archiveuploader/nascentuploadfile.py
@@ -304,11 +304,10 @@ class CustomUploadFile(NascentUploadFile):
 
     def storeInDatabase(self):
         """Create and return the corresponding LibraryFileAlias reference."""
-        libraryfile = self.librarian.create(
-            self.filename, self.size,
-            open(self.filepath, "rb"),
-            self.content_type,
-            restricted=self.policy.archive.private)
+        with open(self.filepath, "rb") as f:
+            libraryfile = self.librarian.create(
+                self.filename, self.size, f, self.content_type,
+                restricted=self.policy.archive.private)
         return libraryfile
 
     def autoApprove(self):
@@ -945,9 +944,10 @@ class BaseBinaryUploadFile(PackageUploadFile):
             user_defined_fields=user_defined_fields,
             debug_package=debug_package)
 
-        library_file = self.librarian.create(self.filename,
-             self.size, open(self.filepath, "rb"), self.content_type,
-             restricted=self.policy.archive.private)
+        with open(self.filepath, "rb") as f:
+            library_file = self.librarian.create(self.filename,
+                 self.size, f, self.content_type,
+                 restricted=self.policy.archive.private)
         binary.addFile(library_file)
         return binary
 
diff --git a/lib/lp/blueprints/browser/specification.py b/lib/lp/blueprints/browser/specification.py
index 6dfd039..310ae20 100644
--- a/lib/lp/blueprints/browser/specification.py
+++ b/lib/lp/blueprints/browser/specification.py
@@ -1424,10 +1424,7 @@ class SpecificationTreeGraphView(LaunchpadView):
         process = Popen(
             cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE,
             close_fds=True)
-        process.stdin.write(input)
-        process.stdin.close()
-        output = process.stdout.read()
-        err = process.stderr.read()
+        output, err = process.communicate(input)
         # XXX Abel Deuring 2012-12-06, bug 1087314
         # err may just contain a warning, while the image might be rendered
         # correctly. We should not raise an error in this case.
diff --git a/lib/lp/services/tarfile_helpers.py b/lib/lp/services/tarfile_helpers.py
index 30f34d6..e9cee0f 100644
--- a/lib/lp/services/tarfile_helpers.py
+++ b/lib/lp/services/tarfile_helpers.py
@@ -49,7 +49,8 @@ class LaunchpadWriteTarFile:
     @classmethod
     def files_to_bytes(cls, files):
         """Turn a dictionary of files into a byte string."""
-        return cls.files_to_stream(files).read()
+        with cls.files_to_stream(files) as stream:
+            return stream.read()
 
     @classmethod
     def files_to_tarfile(cls, files):
diff --git a/lib/lp/soyuz/doc/soyuz-upload.txt b/lib/lp/soyuz/doc/soyuz-upload.txt
index 7962cb2..75ddc0a 100644
--- a/lib/lp/soyuz/doc/soyuz-upload.txt
+++ b/lib/lp/soyuz/doc/soyuz-upload.txt
@@ -608,8 +608,9 @@ and SHA256) for each index published.
 # caused by the absence of published binaries in this suite. It should
 # no happen in real conditions.
 
-    >>> releasefile_contents = open("/var/tmp/archive/ubuntutest/dists/"
-    ...                             "breezy-autotest/Release").read()
+    >>> with open("/var/tmp/archive/ubuntutest/dists/"
+    ...           "breezy-autotest/Release") as f:
+    ...     releasefile_contents = f.read()
     >>> print(releasefile_contents + '\nEND') #doctest: -NORMALIZE_WHITESPACE
     Origin: ubuntutest
     Label: ubuntutest