Merge lp:~mthaddon/codetree/requests-contextlib-1884297 into lp:codetree

Proposed by Tom Haddon
Status: Merged
Approved by: Tom Haddon
Approved revision: 121
Merged at revision: 121
Proposed branch: lp:~mthaddon/codetree/requests-contextlib-1884297
Merge into: lp:codetree
Diff against target: 44 lines (+8/-2)
2 files modified
codetree/handlers/charm.py (+5/-2)
tests/test_charm_handler.py (+3/-0)
To merge this branch: bzr merge lp:~mthaddon/codetree/requests-contextlib-1884297
Reviewer Review Type Date Requested Status
Haw Loeung +1 Approve
Guillermo Gonzalez (community) Approve
Canonical IS Reviewers Pending
Review via email: mp+386189@code.launchpad.net

Commit message

Add a closing wrapper for requests.get per LP:1884297

Description of the change

Add a closing wrapper for requests.get per lp#1884297

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

+1

review: Approve
Revision history for this message
Haw Loeung (hloeung) wrote :

LGTM

review: Approve (+1)
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision 121

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'codetree/handlers/charm.py'
2--- codetree/handlers/charm.py 2020-04-08 09:58:38 +0000
3+++ codetree/handlers/charm.py 2020-06-22 14:39:30 +0000
4@@ -1,6 +1,5 @@
5 from __future__ import division, print_function
6 import hashlib
7-from io import open
8 import json
9 import logging
10 import os
11@@ -9,6 +8,8 @@
12 import subprocess
13 import tempfile
14 import sys
15+from contextlib import closing
16+from io import open
17
18 from .basic import HandlerResult, SourceHandler
19 from .exceptions import InvalidOption, NoSuchCharm
20@@ -160,7 +161,9 @@
21 url = "{0}/{1}/archive".format(self.base_url, self.charmstore_url)
22 zip_path = os.path.join(download_dir, 'charm.zip')
23 calculated_hash = hashlib.new("sha384")
24- with open(zip_path, 'wb') as charm_file, requests.get(url) as req:
25+ # Note that we need the `closing` wrapper for requests.get as it isn't
26+ # a true context manager in python3.4. See LP#1884297.
27+ with open(zip_path, 'wb') as charm_file, closing(requests.get(url)) as req:
28 for chunk in req.iter_content(8192):
29 charm_file.write(chunk)
30 calculated_hash.update(six.ensure_binary(chunk))
31
32=== modified file 'tests/test_charm_handler.py'
33--- tests/test_charm_handler.py 2020-04-08 09:27:18 +0000
34+++ tests/test_charm_handler.py 2020-06-22 14:39:30 +0000
35@@ -58,6 +58,9 @@
36 def __exit__(self, exc_type, exc_val, exc_tb):
37 pass
38
39+ def close(self):
40+ pass
41+
42 @property
43 def content(self):
44 if isinstance(self._content, six.BytesIO):

Subscribers

People subscribed via source and target branches