changeset 36801:eca1051e6c22

util: add public isstdin/isstdout() functions
author Yuya Nishihara <yuya@tcha.org>
date Tue, 06 Mar 2018 02:28:59 -0600
parents 15c050b5d599
children fa53a1d1f16e
files mercurial/util.py
diffstat 1 files changed, 9 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/util.py	Tue Mar 06 03:05:49 2018 -0600
+++ b/mercurial/util.py	Tue Mar 06 02:28:59 2018 -0600
@@ -1430,13 +1430,19 @@
     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 @@
         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: