jenkins-bot has submitted this change. (
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1325952?usp=email )
Change subject: filepage: Close streamed download responses
......................................................................
filepage: Close streamed download responses
FilePage.download relied on content consumption or object cleanup to release
streamed HTTP responses, particularly when a request was unsuccessful.
Manage the response with its context manager so every path closes it before
returning or calculating the downloaded file hash.
Change-Id: Ib0f45d2e01a838682b9ed2858946f850ad73aa3d
---
M pywikibot/page/_filepage.py
1 file changed, 9 insertions(+), 8 deletions(-)
Approvals:
Xqt: Looks good to me, approved
jenkins-bot: Verified
diff --git a/pywikibot/page/_filepage.py b/pywikibot/page/_filepage.py
index d37fba5..bfeb036 100644
--- a/pywikibot/page/_filepage.py
+++ b/pywikibot/page/_filepage.py
@@ -425,16 +425,17 @@
self.site.throttle()
self.site.throttle.set_delays()
- req = http.fetch(url, stream=True)
- if req.status_code == HTTPStatus.OK:
+ with http.fetch(url, stream=True) as response:
+ if response.status_code != HTTPStatus.OK:
+ pywikibot.warning(
+ f'Unsuccessful request ({response.status_code}): '
+ f'{response.url}')
+ return False
+
with path.open('wb') as f:
- f.writelines(req.iter_content(chunk_size))
+ f.writelines(response.iter_content(chunk_size))
- return thumb or compute_file_hash(path) == revision.sha1
-
- pywikibot.warning(
- f'Unsuccessful request ({req.status_code}): {req.url}')
- return False
+ return thumb or compute_file_hash(path) == revision.sha1
def globalusage(self, total=None):
"""Iterate all global usage for this page.
--
To view, visit
https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1325952?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.wikimedia.org/r/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Change-Id: Ib0f45d2e01a838682b9ed2858946f850ad73aa3d
Gerrit-Change-Number: 1325952
Gerrit-PatchSet: 2
Gerrit-Owner: Mahveotm <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
Pywikibot-commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]