mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-26 12:21:26 -07:00
jinja2 cannot handle byte strs with non-ascii. So we need to transform potential byte str into unicode type. This fix is for dynamic inventory.
Fixes #10007
This commit is contained in:
parent
2f1fc3e042
commit
915d232d5f
5 changed files with 42 additions and 4 deletions
|
@ -251,6 +251,24 @@ def json_dict_unicode_to_bytes(d):
|
|||
else:
|
||||
return d
|
||||
|
||||
def json_dict_bytes_to_unicode(d):
|
||||
''' Recursively convert dict keys and values to byte str
|
||||
|
||||
Specialized for json return because this only handles, lists, tuples,
|
||||
and dict container types (the containers that the json module returns)
|
||||
'''
|
||||
|
||||
if isinstance(d, str):
|
||||
return unicode(d, 'utf-8')
|
||||
elif isinstance(d, dict):
|
||||
return dict(map(json_dict_bytes_to_unicode, d.iteritems()))
|
||||
elif isinstance(d, list):
|
||||
return list(map(json_dict_bytes_to_unicode, d))
|
||||
elif isinstance(d, tuple):
|
||||
return tuple(map(json_dict_bytes_to_unicode, d))
|
||||
else:
|
||||
return d
|
||||
|
||||
|
||||
class AnsibleModule(object):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue