diff -r ebe18b90618c Lib/getpass.py --- a/Lib/getpass.py Tue Apr 08 14:58:35 2014 -0400 +++ b/Lib/getpass.py Wed Apr 09 22:55:49 2014 +0530 @@ -19,6 +19,7 @@ import io import os import sys +import locale import warnings __all__ = ["getpass","getuser","GetPassWarning"] @@ -135,7 +136,13 @@ input = sys.stdin prompt = str(prompt) if prompt: - stream.write(prompt) + try: + stream.write(prompt) + except UnicodeEncodeError: + locale_encoding = locale.getpreferredencoding() + prompt = prompt.encode( locale_encoding, 'replace') + prompt = prompt.decode(locale_encoding) + stream.write(prompt) stream.flush() # NOTE: The Python C API calls flockfile() (and unlock) during readline. line = input.readline() diff -r ebe18b90618c Lib/test/test_getpass.py --- a/Lib/test/test_getpass.py Tue Apr 08 14:58:35 2014 -0400 +++ b/Lib/test/test_getpass.py Wed Apr 09 22:55:49 2014 +0530 @@ -4,6 +4,7 @@ from io import BytesIO, StringIO from unittest import mock from test import support +from test.support import run_with_locale try: import termios @@ -69,6 +70,14 @@ getpass._raw_input(stream=StringIO()) mock_input.readline.assert_called_once_with() + @run_with_locale('LC_ALL', 'C') + @mock.patch('sys.stdin') + def test_uses_stdin_as_different_locale(self, mock_input): + mock_input.readline.return_value = "Hasło: " + getpass._raw_input(stream=StringIO()) + mock_input.readline.assert_called_once_with() + + def test_raises_on_empty_input(self): input = StringIO('') self.assertRaises(EOFError, getpass._raw_input, input=input)