From e0bc936b56756a2a9b4982f047335d9be5fc1869 Mon Sep 17 00:00:00 2001 From: Toshio Kuratomi Date: Mon, 5 Mar 2018 12:11:27 -0800 Subject: [PATCH] Python3 issues in maven_artifact (#37035) Fixes #33761 (cherry picked from commit 1bc860fafd9fc25c5bbe2fdcf0db9195a21d380b) --- .../modules/packaging/language/maven_artifact.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/ansible/modules/packaging/language/maven_artifact.py b/lib/ansible/modules/packaging/language/maven_artifact.py index 8a3f23576f..533c73e7b2 100644 --- a/lib/ansible/modules/packaging/language/maven_artifact.py +++ b/lib/ansible/modules/packaging/language/maven_artifact.py @@ -345,8 +345,7 @@ class MavenDownloader: if not self.verify_md5(filename, url + ".md5"): response = self._request(url, "Failed to download artifact " + str(artifact), lambda r: r) if response: - f = open(filename, 'w') - # f.write(response.read()) + f = open(filename, 'wb') self._write_chunks(response, f, report_hook=self.chunk_report) f.close() return True @@ -364,19 +363,19 @@ class MavenDownloader: if bytes_so_far >= total_size: sys.stdout.write('\n') - def _write_chunks(self, response, file, chunk_size=8192, report_hook=None): - total_size = response.info().getheader('Content-Length').strip() + def _write_chunks(self, response, filehandle, chunk_size=8192, report_hook=None): + total_size = response.info().get('Content-Length').strip() total_size = int(total_size) bytes_so_far = 0 - while 1: + while True: chunk = response.read(chunk_size) bytes_so_far += len(chunk) if not chunk: break - file.write(chunk) + filehandle.write(chunk) if report_hook: report_hook(bytes_so_far, chunk_size, total_size)