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 04:15:54 2014 +0530 @@ -135,7 +135,12 @@ input = sys.stdin prompt = str(prompt) if prompt: - stream.write(prompt) + try: + stream.write(prompt) + except UnicodeEncodeError: + prompt = prompt.encode('ascii', 'ignore') + prompt = prompt.decode('ascii') + 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 04:15:54 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)