summaryrefslogtreecommitdiff
path: root/lib/ansible/module_utils/common/text/converters.py
diff options
context:
space:
mode:
Diffstat (limited to 'lib/ansible/module_utils/common/text/converters.py')
-rw-r--r--lib/ansible/module_utils/common/text/converters.py17
1 files changed, 6 insertions, 11 deletions
diff --git a/lib/ansible/module_utils/common/text/converters.py b/lib/ansible/module_utils/common/text/converters.py
index 5b25df47..5b41315b 100644
--- a/lib/ansible/module_utils/common/text/converters.py
+++ b/lib/ansible/module_utils/common/text/converters.py
@@ -10,7 +10,7 @@ import codecs
import datetime
import json
-from ansible.module_utils.common._collections_compat import Set
+from ansible.module_utils.six.moves.collections_abc import Set
from ansible.module_utils.six import (
PY3,
binary_type,
@@ -168,7 +168,7 @@ def to_text(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
handler, otherwise it will use replace.
:surrogate_then_replace: Does the same as surrogate_or_replace but
`was added for symmetry with the error handlers in
- :func:`ansible.module_utils._text.to_bytes` (Added in Ansible 2.3)
+ :func:`ansible.module_utils.common.text.converters.to_bytes` (Added in Ansible 2.3)
Because surrogateescape was added in Python3 this usually means that
Python3 will use `surrogateescape` and Python2 will use the fallback
@@ -179,7 +179,7 @@ def to_text(obj, encoding='utf-8', errors=None, nonstring='simplerepr'):
The default until Ansible-2.2 was `surrogate_or_replace`
In Ansible-2.3 this defaults to `surrogate_then_replace` for symmetry
- with :func:`ansible.module_utils._text.to_bytes` .
+ with :func:`ansible.module_utils.common.text.converters.to_bytes` .
:kwarg nonstring: The strategy to use if a nonstring is specified in
``obj``. Default is 'simplerepr'. Valid values are:
@@ -268,18 +268,13 @@ def _json_encode_fallback(obj):
def jsonify(data, **kwargs):
+ # After 2.18, we should remove this loop, and hardcode to utf-8 in alignment with requiring utf-8 module responses
for encoding in ("utf-8", "latin-1"):
try:
- return json.dumps(data, encoding=encoding, default=_json_encode_fallback, **kwargs)
- # Old systems using old simplejson module does not support encoding keyword.
- except TypeError:
- try:
- new_data = container_to_text(data, encoding=encoding)
- except UnicodeDecodeError:
- continue
- return json.dumps(new_data, default=_json_encode_fallback, **kwargs)
+ new_data = container_to_text(data, encoding=encoding)
except UnicodeDecodeError:
continue
+ return json.dumps(new_data, default=_json_encode_fallback, **kwargs)
raise UnicodeError('Invalid unicode encoding encountered')