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 16:07:05 2013 +0800 @@ -16,6 +16,7 @@ # Gregory P. Smith (tty support & GetPassWarning) import os, sys, warnings +import io __all__ = ["getpass","getuser","GetPassWarning"] @@ -44,7 +45,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 +84,11 @@ del input, tty # clean up unused file objects before blocking passwd = fallback_getpass(prompt, stream) - stream.write('\n') + if type(stream)==io.FileIO: + stream.write(bytes('\n', 'UTF-8')) + stream.close() + else: + stream.write('\n') return passwd @@ -127,7 +132,10 @@ input = sys.stdin prompt = str(prompt) if prompt: - stream.write(prompt) + if type(stream)==io.FileIO: + stream.write(bytes(prompt, 'UTF-8')) + else: + stream.write(prompt) stream.flush() # NOTE: The Python C API calls flockfile() (and unlock) during readline. line = input.readline()