launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26090
[Merge] ~cjwatson/launchpad:py3-urlfetch-context-manager into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-urlfetch-context-manager into launchpad:master.
Commit message:
Use urlfetch's return value as a context manager
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/396827
Fixes ResourceWarnings on Python 3.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-urlfetch-context-manager into launchpad:master.
diff --git a/lib/lp/bugs/scripts/bzremotecomponentfinder.py b/lib/lp/bugs/scripts/bzremotecomponentfinder.py
index cf4246e..8286e73 100644
--- a/lib/lp/bugs/scripts/bzremotecomponentfinder.py
+++ b/lib/lp/bugs/scripts/bzremotecomponentfinder.py
@@ -58,7 +58,8 @@ class BugzillaRemoteComponentScraper:
def getPage(self):
"""Download and return content from the Bugzilla page"""
with override_timeout(config.updatebugzillaremotecomponents.timeout):
- return urlfetch(self.url, use_proxy=True).content
+ with urlfetch(self.url, use_proxy=True) as response:
+ return response.content
def parsePage(self, page_text):
"""Builds self.product using HTML content in page_text"""
diff --git a/lib/lp/bugs/scripts/sfremoteproductfinder.py b/lib/lp/bugs/scripts/sfremoteproductfinder.py
index 66a88fd..952839f 100644
--- a/lib/lp/bugs/scripts/sfremoteproductfinder.py
+++ b/lib/lp/bugs/scripts/sfremoteproductfinder.py
@@ -45,7 +45,8 @@ class SourceForgeRemoteProductFinder:
"""GET the specified page on the remote HTTP server."""
page_url = urlappend(self.sourceforge_baseurl, page)
with override_timeout(config.updatesourceforgeremoteproduct.timeout):
- return urlfetch(page_url, use_proxy=True).content
+ with urlfetch(page_url, use_proxy=True) as response:
+ return response.content
def getRemoteProductFromSourceForge(self, sf_project):
"""Return the remote product of a SourceForge project.
diff --git a/lib/lp/services/gpg/handler.py b/lib/lp/services/gpg/handler.py
index e3eba45..d2ace9e 100644
--- a/lib/lp/services/gpg/handler.py
+++ b/lib/lp/services/gpg/handler.py
@@ -580,7 +580,8 @@ class GPGHandler:
def _grabPage(self, action, fingerprint):
"""Wrapper to collect KeyServer Pages."""
url = self.getURLForKeyInServer(fingerprint, action)
- return urlfetch(url).content
+ with urlfetch(url) as response:
+ return response.content
@implementer(IPymeSignature)
diff --git a/lib/lp/services/scripts/base.py b/lib/lp/services/scripts/base.py
index 094923d..1a47b2d 100644
--- a/lib/lp/services/scripts/base.py
+++ b/lib/lp/services/scripts/base.py
@@ -471,7 +471,8 @@ def cronscript_enabled(control_url, name, log):
# Try reading the config file. If it fails, we log the
# traceback and continue on using the defaults.
try:
- cron_config.readfp(io.StringIO(response.text))
+ with response:
+ cron_config.readfp(io.StringIO(response.text))
except Exception:
log.exception("Error parsing %s", control_url)