comparison mercurial/ui.py @ 10421:452b6195e94c

ui: look before you leap on sys.stderr.closed (and look nicer) f83291e5643e introduced a fix if sys.stdout.closed does not exist. This change uses a getattr with default instead of hasattr (which just calls getattr) and accessing the attribute. Additionally it applies the same fix for sys.stderr.closed as this is not available in the bpython shell (reported by Roger Gammans).
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 12 Feb 2010 15:46:48 +0100
parents f83291e5643e
children 5a3a916aad58
comparison
equal deleted inserted replaced
10420:41d0ed2c79df 10421:452b6195e94c
235 for a in args: 235 for a in args:
236 sys.stdout.write(str(a)) 236 sys.stdout.write(str(a))
237 237
238 def write_err(self, *args): 238 def write_err(self, *args):
239 try: 239 try:
240 if not hasattr(sys.stdout, 'closed') or not sys.stdout.closed: 240 if not getattr(sys.stdout, 'closed', False):
241 sys.stdout.flush() 241 sys.stdout.flush()
242 for a in args: 242 for a in args:
243 sys.stderr.write(str(a)) 243 sys.stderr.write(str(a))
244 # stderr may be buffered under win32 when redirected to files, 244 # stderr may be buffered under win32 when redirected to files,
245 # including stdout. 245 # including stdout.
246 if not sys.stderr.closed: 246 if not getattr(sys.stderr, 'closed', False):
247 sys.stderr.flush() 247 sys.stderr.flush()
248 except IOError, inst: 248 except IOError, inst:
249 if inst.errno != errno.EPIPE: 249 if inst.errno != errno.EPIPE:
250 raise 250 raise
251 251