ui: look before you leap on sys.stderr.closed (and look nicer)
authorThomas Arendsen Hein <thomas@intevation.de>
Fri, 12 Feb 2010 15:46:48 +0100
changeset 10421 452b6195e94c
parent 10420 41d0ed2c79df
child 10426 5a3a916aad58
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).
mercurial/ui.py
--- a/mercurial/ui.py	Thu Feb 11 17:44:01 2010 -0600
+++ b/mercurial/ui.py	Fri Feb 12 15:46:48 2010 +0100
@@ -237,13 +237,13 @@
 
     def write_err(self, *args):
         try:
-            if not hasattr(sys.stdout, 'closed') or not sys.stdout.closed:
+            if not getattr(sys.stdout, 'closed', False):
                 sys.stdout.flush()
             for a in args:
                 sys.stderr.write(str(a))
             # stderr may be buffered under win32 when redirected to files,
             # including stdout.
-            if not sys.stderr.closed:
+            if not getattr(sys.stderr, 'closed', False):
                 sys.stderr.flush()
         except IOError, inst:
             if inst.errno != errno.EPIPE: