diff options
| author | Toshio Kuratomi <toshio@fedoraproject.org> | 2015-10-12 10:05:19 -0700 |
|---|---|---|
| committer | Toshio Kuratomi <toshio@fedoraproject.org> | 2015-10-12 10:06:13 -0700 |
| commit | b441bcb678ca86c71b1f54f784df0db76453181c (patch) | |
| tree | caf45d83a51846e1a17f88fc01d375cd3680fa55 | |
| parent | d15fcf05f09728832ee982166b02f26cd3c9f8d2 (diff) | |
| download | ansible-b441bcb678ca86c71b1f54f784df0db76453181c.tar.gz | |
Fix display when run through a testing framework that overrides stderr/stdout
| -rw-r--r-- | lib/ansible/utils/display.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py index 5c392af8da..88e1a56804 100644 --- a/lib/ansible/utils/display.py +++ b/lib/ansible/utils/display.py @@ -26,6 +26,7 @@ import random import subprocess import sys import time +import locale import logging import getpass from struct import unpack, pack @@ -267,9 +268,13 @@ class Display: @staticmethod def _output_encoding(stderr=False): - if stderr: - return sys.stderr.encoding or 'utf-8' - return sys.stdout.encoding or 'utf-8' + encoding = locale.getpreferredencoding() + # https://bugs.python.org/issue6202 + # Python2 hardcodes an obsolete value on Mac. Use MacOSX defaults + # instead. + if encoding in ('mac-roman',): + encoding = 'utf-8' + return encoding def _set_column_width(self): if os.isatty(0): |
