]> granicus.if.org Git - python/commitdiff
Fix shutil.get_terminal_size() error handling
authorVictor Stinner <victor.stinner@gmail.com>
Tue, 19 Apr 2016 20:24:56 +0000 (22:24 +0200)
committerVictor Stinner <victor.stinner@gmail.com>
Tue, 19 Apr 2016 20:24:56 +0000 (22:24 +0200)
Issue #26801: Fix error handling in shutil.get_terminal_size(), catch
AttributeError instead of NameError. Patch written by Emanuel Barry.

test_shutil: skip the functional test using "stty size" command if
os.get_terminal_size() is missing.

Lib/shutil.py
Lib/test/test_shutil.py
Misc/ACKS
Misc/NEWS

index 3f4b6bf663ffbbde199aa5377637ba7ceb0066a7..7f8edf5e5a30a723dba867429985c4424ff20adc 100644 (file)
@@ -1069,7 +1069,7 @@ def get_terminal_size(fallback=(80, 24)):
     if columns <= 0 or lines <= 0:
         try:
             size = os.get_terminal_size(sys.__stdout__.fileno())
-        except (NameError, OSError):
+        except (AttributeError, OSError):
             size = os.terminal_size(fallback)
         if columns <= 0:
             columns = size.columns
index ca1d0067634bae7c5a9fc326d3536f4d75383c0a..7e41891e5ee110961d9e421db857f9778ec92058 100644 (file)
@@ -1837,6 +1837,8 @@ class TermsizeTests(unittest.TestCase):
         self.assertEqual(size.lines, 888)
 
     @unittest.skipUnless(os.isatty(sys.__stdout__.fileno()), "not on tty")
+    @unittest.skipUnless(hasattr(os, 'get_terminal_size'),
+                         'need os.get_terminal_size()')
     def test_stty_match(self):
         """Check if stty returns the same results ignoring env
 
index e293ddc9c6d151875e3b06f652103fedf1a952a3..6c01880eeafb343ac755b5364e9a5fb507673222 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -90,6 +90,7 @@ Matthew Barnett
 Richard Barran
 Cesar Eduardo Barros
 Des Barry
+Emanuel Barry
 Ulf Bartelt
 Campbell Barton
 Don Bashford
index 86caea80c8856ef4be2c9c6b30926fdb0e821ee1..0cb29ad257b5877cc4c49e61d218088feba89ae2 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -107,6 +107,10 @@ Core and Builtins
 Library
 -------
 
+- Issue #26801: Fix error handling in :func:`shutil.get_terminal_size`, catch
+  :exc:`AttributeError` instead of :exc:`NameError`. Patch written by Emanuel
+  Barry.
+
 - Issue #24838: tarfile's ustar and gnu formats now correctly calculate name
   and link field limits for multibyte character encodings like utf-8.