mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Set prompt encoding to a sane value when sys.stdout.encoding is None
Fixes #8644
This commit is contained in:
parent
379e31883c
commit
c8494cdc39
1 changed files with 8 additions and 1 deletions
|
@ -25,6 +25,7 @@ import fnmatch
|
|||
import tempfile
|
||||
import fcntl
|
||||
import constants
|
||||
import locale
|
||||
from ansible.color import stringc
|
||||
|
||||
import logging
|
||||
|
@ -645,7 +646,13 @@ class PlaybookCallbacks(object):
|
|||
msg = 'input for %s: ' % varname
|
||||
|
||||
def prompt(prompt, private):
|
||||
if sys.stdout.encoding:
|
||||
msg = prompt.encode(sys.stdout.encoding)
|
||||
else:
|
||||
# when piping the output, or at other times when stdout
|
||||
# may not be the standard file descriptor, the stdout
|
||||
# encoding may not be set, so default to something sane
|
||||
msg = prompt.encode(locale.getpreferredencoding())
|
||||
if private:
|
||||
return getpass.getpass(msg)
|
||||
return raw_input(msg)
|
||||
|
|
Loading…
Reference in a new issue