# HG changeset patch # User Yuya Nishihara # Date 2018-03-06 08:28:59 # Node ID eca1051e6c224d7e4fb1bd166bf1ab33ccb084c9 # Parent 15c050b5d5997f1af3f23c7915b9589361e0d73e util: add public isstdin/isstdout() functions diff --git a/mercurial/util.py b/mercurial/util.py --- a/mercurial/util.py +++ b/mercurial/util.py @@ -1430,13 +1430,19 @@ def _sethgexecutable(path): global _hgexecutable _hgexecutable = path -def _isstdout(f): +def _testfileno(f, stdf): fileno = getattr(f, 'fileno', None) try: - return fileno and fileno() == sys.__stdout__.fileno() + return fileno and fileno() == stdf.fileno() except io.UnsupportedOperation: return False # fileno() raised UnsupportedOperation +def isstdin(f): + return _testfileno(f, sys.__stdin__) + +def isstdout(f): + return _testfileno(f, sys.__stdout__) + def shellenviron(environ=None): """return environ with optional override, useful for shelling out""" def py2shell(val): @@ -1464,7 +1470,7 @@ def system(cmd, environ=None, cwd=None, pass cmd = quotecommand(cmd) env = shellenviron(environ) - if out is None or _isstdout(out): + if out is None or isstdout(out): rc = subprocess.call(cmd, shell=True, close_fds=closefds, env=env, cwd=cwd) else: