[PATCH] pager: check for stdout.isatty in a try block

Idan Kamara idankk86 at gmail.com
Wed Jun 1 16:56:15 CDT 2011


# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1306964614 -10800
# Node ID 0ded137fb830436f8668f9745041b3ab6d9d4be9
# Parent  eccbb9980ada13088722a3ab88117cb8c8c8c37e
pager: check for stdout.isatty in a try block

stdout may not have a isatty attribute.

also, move some checks to uisetup() to save
needless wrapping.

diff -r eccbb9980ada -r 0ded137fb830 hgext/pager.py
--- a/hgext/pager.py	Thu Jun 02 00:43:34 2011 +0300
+++ b/hgext/pager.py	Thu Jun 02 00:43:34 2011 +0300
@@ -86,12 +86,19 @@
             raise
 
 def uisetup(ui):
-    if ui.plain():
+    def isatty():
+        try:
+            return sys.stdout.isatty()
+        except AttributeError:
+            return False
+
+    if ui.plain() or '--debugger' in sys.argv or not isatty():
         return
 
     def pagecmd(orig, ui, options, cmd, cmdfunc):
         p = ui.config("pager", "pager", os.environ.get("PAGER"))
-        if p and sys.stdout.isatty() and '--debugger' not in sys.argv:
+
+        if p:
             attend = ui.configlist('pager', 'attend', attended)
             auto = options['pager'] == 'auto'
             always = util.parsebool(options['pager'])


More information about the Mercurial-devel mailing list