Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commandserver.py @ 30482:39d13b8c101d
py3: bulk replace sys.stdin/out/err by util's
Almost all sys.stdin/out/err in hgext/ and mercurial/ are replaced by util's.
There are a few exceptions:
- lsprof.py and statprof.py are untouched since they are a kind of vendor
code and they never import mercurial modules right now.
- ui._readline() needs to replace sys.stdin and stdout to pass them to
raw_input(). We'll need another workaround here.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Thu, 20 Oct 2016 23:53:36 +0900 |
parents | 7f2313450e86 |
children | dd539e2d89aa |
comparison
equal
deleted
inserted
replaced
30481:277f4fe6d01a | 30482:39d13b8c101d |
---|---|
13 import random | 13 import random |
14 import select | 14 import select |
15 import signal | 15 import signal |
16 import socket | 16 import socket |
17 import struct | 17 import struct |
18 import sys | |
19 import traceback | 18 import traceback |
20 | 19 |
21 from .i18n import _ | 20 from .i18n import _ |
22 from . import ( | 21 from . import ( |
23 encoding, | 22 encoding, |
302 def _protectio(ui): | 301 def _protectio(ui): |
303 """ duplicates streams and redirect original to null if ui uses stdio """ | 302 """ duplicates streams and redirect original to null if ui uses stdio """ |
304 ui.flush() | 303 ui.flush() |
305 newfiles = [] | 304 newfiles = [] |
306 nullfd = os.open(os.devnull, os.O_RDWR) | 305 nullfd = os.open(os.devnull, os.O_RDWR) |
307 for f, sysf, mode in [(ui.fin, sys.stdin, 'rb'), | 306 for f, sysf, mode in [(ui.fin, util.stdin, 'rb'), |
308 (ui.fout, sys.stdout, 'wb')]: | 307 (ui.fout, util.stdout, 'wb')]: |
309 if f is sysf: | 308 if f is sysf: |
310 newfd = os.dup(f.fileno()) | 309 newfd = os.dup(f.fileno()) |
311 os.dup2(nullfd, f.fileno()) | 310 os.dup2(nullfd, f.fileno()) |
312 f = os.fdopen(newfd, mode) | 311 f = os.fdopen(newfd, mode) |
313 newfiles.append(f) | 312 newfiles.append(f) |