84 # Python 3 implements its own I/O streams. |
84 # Python 3 implements its own I/O streams. |
85 # TODO: .buffer might not exist if std streams were replaced; we'll need |
85 # TODO: .buffer might not exist if std streams were replaced; we'll need |
86 # a silly wrapper to make a bytes stream backed by a unicode one. |
86 # a silly wrapper to make a bytes stream backed by a unicode one. |
87 stdin = sys.stdin.buffer |
87 stdin = sys.stdin.buffer |
88 stdout = sys.stdout.buffer |
88 stdout = sys.stdout.buffer |
89 stderr = sys.stderr.buffer |
|
90 if isatty(stdout): |
89 if isatty(stdout): |
91 # The standard library doesn't offer line-buffered binary streams. |
90 # The standard library doesn't offer line-buffered binary streams. |
92 stdout = make_line_buffered(stdout) |
91 stdout = make_line_buffered(stdout) |
|
92 stderr = sys.stderr.buffer |
93 else: |
93 else: |
94 # Python 2 uses the I/O streams provided by the C library. |
94 # Python 2 uses the I/O streams provided by the C library. |
95 stdin = sys.stdin |
95 stdin = sys.stdin |
96 stdout = sys.stdout |
96 stdout = sys.stdout |
97 stderr = sys.stderr |
|
98 if isatty(stdout): |
97 if isatty(stdout): |
99 if pycompat.iswindows: |
98 if pycompat.iswindows: |
100 # Work around size limit when writing to console. |
99 # Work around size limit when writing to console. |
101 stdout = platform.winstdout(stdout) |
100 stdout = platform.winstdout(stdout) |
102 # The Windows C runtime library doesn't support line buffering. |
101 # The Windows C runtime library doesn't support line buffering. |
104 else: |
103 else: |
105 # glibc determines buffering on first write to stdout - if we |
104 # glibc determines buffering on first write to stdout - if we |
106 # replace a TTY destined stdout with a pipe destined stdout (e.g. |
105 # replace a TTY destined stdout with a pipe destined stdout (e.g. |
107 # pager), we want line buffering. |
106 # pager), we want line buffering. |
108 stdout = os.fdopen(stdout.fileno(), 'wb', 1) |
107 stdout = os.fdopen(stdout.fileno(), 'wb', 1) |
|
108 stderr = sys.stderr |
109 |
109 |
110 |
110 |
111 findexe = platform.findexe |
111 findexe = platform.findexe |
112 _gethgcmd = platform.gethgcmd |
112 _gethgcmd = platform.gethgcmd |
113 getuser = platform.getuser |
113 getuser = platform.getuser |