Merge ~cjwatson/launchpad:py3-urlfetch-context-manager into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 105504f11cee78226d1e0017f7e931d082d8dc23
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-urlfetch-context-manager
Merge into: launchpad:master
Diff against target: 55 lines (+8/-4)
4 files modified
lib/lp/bugs/scripts/bzremotecomponentfinder.py (+2/-1)
lib/lp/bugs/scripts/sfremoteproductfinder.py (+2/-1)
lib/lp/services/gpg/handler.py (+2/-1)
lib/lp/services/scripts/base.py (+2/-1)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+396827@code.launchpad.net

Commit message

Use urlfetch's return value as a context manager

Description of the change

Fixes ResourceWarnings on Python 3.

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/bugs/scripts/bzremotecomponentfinder.py b/lib/lp/bugs/scripts/bzremotecomponentfinder.py
2index cf4246e..8286e73 100644
3--- a/lib/lp/bugs/scripts/bzremotecomponentfinder.py
4+++ b/lib/lp/bugs/scripts/bzremotecomponentfinder.py
5@@ -58,7 +58,8 @@ class BugzillaRemoteComponentScraper:
6 def getPage(self):
7 """Download and return content from the Bugzilla page"""
8 with override_timeout(config.updatebugzillaremotecomponents.timeout):
9- return urlfetch(self.url, use_proxy=True).content
10+ with urlfetch(self.url, use_proxy=True) as response:
11+ return response.content
12
13 def parsePage(self, page_text):
14 """Builds self.product using HTML content in page_text"""
15diff --git a/lib/lp/bugs/scripts/sfremoteproductfinder.py b/lib/lp/bugs/scripts/sfremoteproductfinder.py
16index 66a88fd..952839f 100644
17--- a/lib/lp/bugs/scripts/sfremoteproductfinder.py
18+++ b/lib/lp/bugs/scripts/sfremoteproductfinder.py
19@@ -45,7 +45,8 @@ class SourceForgeRemoteProductFinder:
20 """GET the specified page on the remote HTTP server."""
21 page_url = urlappend(self.sourceforge_baseurl, page)
22 with override_timeout(config.updatesourceforgeremoteproduct.timeout):
23- return urlfetch(page_url, use_proxy=True).content
24+ with urlfetch(page_url, use_proxy=True) as response:
25+ return response.content
26
27 def getRemoteProductFromSourceForge(self, sf_project):
28 """Return the remote product of a SourceForge project.
29diff --git a/lib/lp/services/gpg/handler.py b/lib/lp/services/gpg/handler.py
30index e3eba45..d2ace9e 100644
31--- a/lib/lp/services/gpg/handler.py
32+++ b/lib/lp/services/gpg/handler.py
33@@ -580,7 +580,8 @@ class GPGHandler:
34 def _grabPage(self, action, fingerprint):
35 """Wrapper to collect KeyServer Pages."""
36 url = self.getURLForKeyInServer(fingerprint, action)
37- return urlfetch(url).content
38+ with urlfetch(url) as response:
39+ return response.content
40
41
42 @implementer(IPymeSignature)
43diff --git a/lib/lp/services/scripts/base.py b/lib/lp/services/scripts/base.py
44index 094923d..1a47b2d 100644
45--- a/lib/lp/services/scripts/base.py
46+++ b/lib/lp/services/scripts/base.py
47@@ -471,7 +471,8 @@ def cronscript_enabled(control_url, name, log):
48 # Try reading the config file. If it fails, we log the
49 # traceback and continue on using the defaults.
50 try:
51- cron_config.readfp(io.StringIO(response.text))
52+ with response:
53+ cron_config.readfp(io.StringIO(response.text))
54 except Exception:
55 log.exception("Error parsing %s", control_url)
56

Subscribers

People subscribed via source and target branches

to status/vote changes: