mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Fix display when run through a testing framework that overrides stderr/stdout
This commit is contained in:
parent
d15fcf05f0
commit
b441bcb678
1 changed files with 8 additions and 3 deletions
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue