From 4af16d0c767a5a462d4c669eb3f9e88698f0432c Mon Sep 17 00:00:00 2001 From: Michael Steffens <30410322+MichaelSteffens@users.noreply.github.com> Date: Tue, 17 Jul 2018 23:52:49 +0200 Subject: [PATCH] Python3: compare bytes with bytes and strings with strings. (Fixes #42677) (#42878) --- lib/ansible/modules/packaging/language/maven_artifact.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/ansible/modules/packaging/language/maven_artifact.py b/lib/ansible/modules/packaging/language/maven_artifact.py index 25b4717929d..02afe130b13 100644 --- a/lib/ansible/modules/packaging/language/maven_artifact.py +++ b/lib/ansible/modules/packaging/language/maven_artifact.py @@ -177,7 +177,7 @@ except ImportError: from ansible.module_utils.basic import AnsibleModule from ansible.module_utils.six.moves.urllib.parse import urlparse from ansible.module_utils.urls import fetch_url -from ansible.module_utils._text import to_bytes +from ansible.module_utils._text import to_bytes, to_native, to_text def split_pre_existing_dir(dirname): @@ -428,7 +428,10 @@ class MavenDownloader: parsed_url = urlparse(remote_url) remote_md5 = self._local_md5(parsed_url.path) else: - remote_md5 = self._getContent(remote_url + '.md5', "Failed to retrieve MD5", False) + try: + remote_md5 = to_text(self._getContent(remote_url + '.md5', "Failed to retrieve MD5", False), errors='strict') + except UnicodeError as e: + return "Cannot retrieve a valid md5 from %s: %s" % (remote_url, to_native(e)) if(not remote_md5): return "Cannot find md5 from " + remote_url if local_md5 == remote_md5: @@ -441,7 +444,7 @@ class MavenDownloader: def _local_md5(self, file): md5 = hashlib.md5() with io.open(file, 'rb') as f: - for chunk in iter(lambda: f.read(8192), ''): + for chunk in iter(lambda: f.read(8192), b''): md5.update(chunk) return md5.hexdigest()