diff options
author | Matt Martz <matt@sivel.net> | 2023-04-18 12:01:47 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-18 12:01:47 -0500 |
commit | f90c7f1a7d38f317b3d22977f06ef1b15311a4a7 (patch) | |
tree | 09f8954d189f770624298e35164ba9a8df41f2c4 /lib/ansible/utils/display.py | |
parent | 12083db2c535f2de0c50c5fb14a47e43c289f703 (diff) | |
download | ansible-f90c7f1a7d38f317b3d22977f06ef1b15311a4a7.tar.gz |
[stable-2.15] Implement checks, and backwards compat change, to move forward with UTF-8 only (#80370) (#80545)
(cherry picked from commit 0ee7cfb)
Diffstat (limited to 'lib/ansible/utils/display.py')
-rw-r--r-- | lib/ansible/utils/display.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/lib/ansible/utils/display.py b/lib/ansible/utils/display.py index b4ff01c006..7f059a16a6 100644 --- a/lib/ansible/utils/display.py +++ b/lib/ansible/utils/display.py @@ -26,6 +26,7 @@ else: # this will be set to False if curses.setupterm() fails HAS_CURSES = True +import codecs import ctypes.util import fcntl import getpass @@ -297,8 +298,24 @@ class Display(metaclass=Singleton): except Exception as ex: self.warning(f"failed to patch stdout/stderr for fork-safety: {ex}") + codecs.register_error('_replacing_warning_handler', self._replacing_warning_handler) + try: + sys.stdout.reconfigure(errors='_replacing_warning_handler') + sys.stderr.reconfigure(errors='_replacing_warning_handler') + except Exception as ex: + self.warning(f"failed to reconfigure stdout/stderr with custom encoding error handler: {ex}") + self.setup_curses = False + def _replacing_warning_handler(self, exception): + # TODO: This should probably be deferred until after the current display is completed + # this will require some amount of new functionality + self.deprecated( + 'Non UTF-8 encoded data replaced with "?" while displaying text to stdout/stderr, this is temporary and will become an error', + version='2.18', + ) + return '?', exception.end + def set_queue(self, queue): """Set the _final_q on Display, so that we know to proxy display over the queue instead of directly writing to stdout/stderr from forks |