diff -r 0ebc9005cb00 Lib/getpass.py --- a/Lib/getpass.py Thu May 30 21:08:49 2013 -0400 +++ b/Lib/getpass.py Sun Jun 02 15:49:49 2013 +0800 @@ -44,7 +44,7 @@ try: # Always try reading and writing directly on the tty first. fd = os.open('/dev/tty', os.O_RDWR|os.O_NOCTTY) - tty = os.fdopen(fd, 'w+', 1) + tty = os.fdopen(fd, 'wb+', buffering=0) input = tty if not stream: stream = tty @@ -83,7 +83,9 @@ del input, tty # clean up unused file objects before blocking passwd = fallback_getpass(prompt, stream) - stream.write('\n') + stream.write(bytes('\n', 'UTF-8')) + if stream==tty: + stream.close() return passwd @@ -127,7 +129,7 @@ input = sys.stdin prompt = str(prompt) if prompt: - stream.write(prompt) + stream.write(bytes(prompt, 'UTF-8')) stream.flush() # NOTE: The Python C API calls flockfile() (and unlock) during readline. line = input.readline()