comparison mercurial/util.py @ 36462:1ca4e86c7265

util: handle fileno() on Python 3 throwing io.UnsupportedOperation Fortunately, the exception exists on Python 2 so we don't have to do something weirder than this. Differential Revision: https://phab.mercurial-scm.org/D2450
author Augie Fackler <augie@google.com>
date Mon, 26 Feb 2018 00:51:41 -0500
parents 04c319a07c7b
children bfe38f787d5b
comparison
equal deleted inserted replaced
36461:ec43960b03e8 36462:1ca4e86c7265
24 import datetime 24 import datetime
25 import errno 25 import errno
26 import gc 26 import gc
27 import hashlib 27 import hashlib
28 import imp 28 import imp
29 import io
29 import itertools 30 import itertools
30 import mmap 31 import mmap
31 import os 32 import os
32 import platform as pyplatform 33 import platform as pyplatform
33 import re as remod 34 import re as remod
1176 global _hgexecutable 1177 global _hgexecutable
1177 _hgexecutable = path 1178 _hgexecutable = path
1178 1179
1179 def _isstdout(f): 1180 def _isstdout(f):
1180 fileno = getattr(f, 'fileno', None) 1181 fileno = getattr(f, 'fileno', None)
1181 return fileno and fileno() == sys.__stdout__.fileno() 1182 try:
1183 return fileno and fileno() == sys.__stdout__.fileno()
1184 except io.UnsupportedOperation:
1185 return False # fileno() raised UnsupportedOperation
1182 1186
1183 def shellenviron(environ=None): 1187 def shellenviron(environ=None):
1184 """return environ with optional override, useful for shelling out""" 1188 """return environ with optional override, useful for shelling out"""
1185 def py2shell(val): 1189 def py2shell(val):
1186 'convert python object into string that is useful to shell' 1190 'convert python object into string that is useful to shell'