mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Merge pull request #5178 from cavassin/devel
Prevents UnicodeEncodeError
This commit is contained in:
commit
cd3144af5d
2 changed files with 12 additions and 3 deletions
|
@ -128,9 +128,15 @@ def display(msg, color=None, stderr=False, screen_only=False, log_only=False, ru
|
||||||
msg2 = stringc(msg, color)
|
msg2 = stringc(msg, color)
|
||||||
if not log_only:
|
if not log_only:
|
||||||
if not stderr:
|
if not stderr:
|
||||||
print msg2
|
try:
|
||||||
|
print msg2
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
print msg2.encode('utf-8')
|
||||||
else:
|
else:
|
||||||
print >>sys.stderr, msg2
|
try:
|
||||||
|
print >>sys.stderr, msg2
|
||||||
|
except UnicodeEncodeError:
|
||||||
|
print >>sys.stderr, msg2.encode('utf-8')
|
||||||
if constants.DEFAULT_LOG_PATH != '':
|
if constants.DEFAULT_LOG_PATH != '':
|
||||||
while msg.startswith("\n"):
|
while msg.startswith("\n"):
|
||||||
msg = msg.replace("\n","")
|
msg = msg.replace("\n","")
|
||||||
|
|
|
@ -136,7 +136,10 @@ class ModuleReplacer(object):
|
||||||
complex_args_json = utils.jsonify(complex_args)
|
complex_args_json = utils.jsonify(complex_args)
|
||||||
# We force conversion of module_args to str because module_common calls shlex.split,
|
# We force conversion of module_args to str because module_common calls shlex.split,
|
||||||
# a standard library function that incorrectly handles Unicode input before Python 2.7.3.
|
# a standard library function that incorrectly handles Unicode input before Python 2.7.3.
|
||||||
encoded_args = repr(module_args.encode('utf-8'))
|
try:
|
||||||
|
encoded_args = repr(module_args.encode('utf-8'))
|
||||||
|
except UnicodeDecodeError:
|
||||||
|
encoded_args = repr(module_args)
|
||||||
encoded_lang = repr(C.DEFAULT_MODULE_LANG)
|
encoded_lang = repr(C.DEFAULT_MODULE_LANG)
|
||||||
encoded_complex = repr(complex_args_json)
|
encoded_complex = repr(complex_args_json)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue