Python3: compare bytes with bytes and strings with strings. (Fixes #42677) (#42878)

pull/38244/head^2
Michael Steffens 6 years ago committed by ansibot
parent 95a1170908
commit 4af16d0c76

@ -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()

Loading…
Cancel
Save