[Python-checkins] cpython (3.5): Fix shutil.get_terminal_size() error handling
victor.stinner
python-checkins at python.org
Tue Apr 19 16:29:34 EDT 2016
https://hg.python.org/cpython/rev/e3763b5964b6
changeset: 101066:e3763b5964b6
branch: 3.5
parent: 101064:376bee0d1b37
user: Victor Stinner <victor.stinner at gmail.com>
date: Tue Apr 19 22:24:56 2016 +0200
summary:
Fix shutil.get_terminal_size() error handling
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.
files:
Lib/shutil.py | 2 +-
Lib/test/test_shutil.py | 2 ++
Misc/ACKS | 1 +
Misc/NEWS | 4 ++++
4 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/Lib/shutil.py b/Lib/shutil.py
--- a/Lib/shutil.py
+++ b/Lib/shutil.py
@@ -1069,7 +1069,7 @@
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
diff --git a/Lib/test/test_shutil.py b/Lib/test/test_shutil.py
--- a/Lib/test/test_shutil.py
+++ b/Lib/test/test_shutil.py
@@ -1837,6 +1837,8 @@
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
diff --git a/Misc/ACKS b/Misc/ACKS
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -90,6 +90,7 @@
Richard Barran
Cesar Eduardo Barros
Des Barry
+Emanuel Barry
Ulf Bartelt
Campbell Barton
Don Bashford
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -107,6 +107,10 @@
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.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list