summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToshio Kuratomi <toshio@fedoraproject.org>2015-10-01 07:28:56 -0700
committerToshio Kuratomi <toshio@fedoraproject.org>2015-10-01 07:51:49 -0700
commitf79993c0b0cbee81f1079e8183202de960bf7b1b (patch)
tree7a3fed36fe69521baf6a05c2c58e30d269eb4484
parentfe0e4f27ad82c4b5844a3a18922fa1857242a33b (diff)
downloadansible-py3-unicode-exec.tar.gz
Since Connection.execute_command() returns bytes, deal with the repurcussions here.py3-unicode-exec
-rw-r--r--lib/ansible/plugins/action/__init__.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/lib/ansible/plugins/action/__init__.py b/lib/ansible/plugins/action/__init__.py
index 25fe03192e..a4e8d84423 100644
--- a/lib/ansible/plugins/action/__init__.py
+++ b/lib/ansible/plugins/action/__init__.py
@@ -27,14 +27,14 @@ import stat
import tempfile
import time
-from six import string_types
+from six import binary_type, text_type
from six.moves import StringIO
from ansible import constants as C
from ansible.errors import AnsibleError, AnsibleConnectionFailure
from ansible.executor.module_common import modify_module
from ansible.parsing.utils.jsonify import jsonify
-from ansible.utils.unicode import to_bytes
+from ansible.utils.unicode import to_bytes, to_unicode
try:
from __main__ import display
@@ -472,13 +472,23 @@ class ActionBase:
rc, stdout, stderr = self._connection.exec_command(cmd, in_data=in_data, sudoable=sudoable)
self._display.debug("command execution done")
- if not isinstance(stdout, string_types):
- out = ''.join(stdout.readlines())
+ # stdout and stderr may be either a file-like or a bytes object.
+ # Convert either one to a text type
+ # Note: when we address non-utf-8 data we'll have to figure out
+ # a better strategy than errors='strict'. Perhaps pass the
+ # errors argument into this method so that the caller can decide or
+ # even make the caller convert to text type so they can choose.
+ if isinstance(stdout, binary_type):
+ out = to_unicode(stdout, errors='strict')
+ elif not isinstance(stdout, text_type):
+ out = to_unicode(b''.join(stdout.readlines()), errors='strict')
else:
out = stdout
- if not isinstance(stderr, string_types):
- err = ''.join(stderr.readlines())
+ if isinstance(stderr, binary_type):
+ err = to_unicode(stderr, errors='strict')
+ elif not isinstance(stderr, text_type):
+ err = to_unicode(b''.join(stderr.readlines()), errors='strict')
else:
err = stderr