mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
Move uses of to_bytes, to_text, to_native to use the module_utils version (#17423)
We couldn't copy to_unicode, to_bytes, to_str into module_utils because of licensing. So once created it we had two sets of functions that did the same things but had different implementations. To remedy that, this change removes the ansible.utils.unicode versions of those functions.
This commit is contained in:
parent
7a9395b5e0
commit
4ed88512e4
89 changed files with 759 additions and 894 deletions
|
@ -39,14 +39,14 @@ except ImportError:
|
|||
_md5 = None
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.utils.unicode import to_bytes
|
||||
from ansible.module_utils._text import to_bytes
|
||||
|
||||
|
||||
def secure_hash_s(data, hash_func=sha1):
|
||||
''' Return a secure hash hex digest of data. '''
|
||||
|
||||
digest = hash_func()
|
||||
data = to_bytes(data, errors='strict')
|
||||
data = to_bytes(data, errors='surrogate_or_strict')
|
||||
digest.update(data)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
@ -54,12 +54,12 @@ def secure_hash_s(data, hash_func=sha1):
|
|||
def secure_hash(filename, hash_func=sha1):
|
||||
''' Return a secure hash hex digest of local file, None if file is not present or a directory. '''
|
||||
|
||||
if not os.path.exists(to_bytes(filename, errors='strict')) or os.path.isdir(to_bytes(filename, errors='strict')):
|
||||
if not os.path.exists(to_bytes(filename, errors='surrogate_or_strict')) or os.path.isdir(to_bytes(filename, errors='strict')):
|
||||
return None
|
||||
digest = hash_func()
|
||||
blocksize = 64 * 1024
|
||||
try:
|
||||
infile = open(to_bytes(filename, errors='strict'), 'rb')
|
||||
infile = open(to_bytes(filename, errors='surrogate_or_strict'), 'rb')
|
||||
block = infile.read(blocksize)
|
||||
while block:
|
||||
digest.update(block)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue