Patchwork D2450: util: handle fileno() on Python 3 throwing io.UnsupportedOperation

login
register
mail settings
Submitter phabricator
Date Feb. 26, 2018, 1:13 p.m.
Message ID <daa824a54fc96d47ca343d5d56b5ba81@localhost.localdomain>
Download mbox | patch
Permalink /patch/28404/
State Not Applicable
Headers show

Comments

phabricator - Feb. 26, 2018, 1:13 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG1ca4e86c7265: util: handle fileno() on Python 3 throwing io.UnsupportedOperation (authored by durin42, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D2450?vs=6105&id=6122

REVISION DETAIL
  https://phab.mercurial-scm.org/D2450

AFFECTED FILES
  mercurial/util.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -26,6 +26,7 @@ 
 import gc
 import hashlib
 import imp
+import io
 import itertools
 import mmap
 import os
@@ -1178,7 +1179,10 @@ 
 
 def _isstdout(f):
     fileno = getattr(f, 'fileno', None)
-    return fileno and fileno() == sys.__stdout__.fileno()
+    try:
+        return fileno and fileno() == sys.__stdout__.fileno()
+    except io.UnsupportedOperation:
+        return False # fileno() raised UnsupportedOperation
 
 def shellenviron(environ=None):
     """return environ with optional override, useful for shelling out"""