Issue #134: use requests.get as a context manager

This commit is contained in:
Michael Penkov
2017-10-28 16:19:05 +02:00
parent eabc79c8ec
commit 3e7898a987
2 changed files with 7 additions and 2 deletions

View File

@ -29,8 +29,7 @@ def execute(path, *args, **kwargs):
raise ValueError('download command currently supports examples only')
examples_path = re.sub('^examples/', '', path)
output_path = bonobo.get_examples_path(examples_path)
response = _open_url(EXAMPLES_BASE_URL + examples_path)
with open(output_path, 'wb') as fout:
with _open_url(EXAMPLES_BASE_URL + examples_path) as response, open(output_path, 'wb') as fout:
_write_response(response, fout)
print('saved to {}'.format(output_path))