Kaydet (Commit) 119ebb70 authored tarafından Victor Stinner's avatar Victor Stinner

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.
üst ded4c496
...@@ -1069,7 +1069,7 @@ def get_terminal_size(fallback=(80, 24)): ...@@ -1069,7 +1069,7 @@ def get_terminal_size(fallback=(80, 24)):
if columns <= 0 or lines <= 0: if columns <= 0 or lines <= 0:
try: try:
size = os.get_terminal_size(sys.__stdout__.fileno()) size = os.get_terminal_size(sys.__stdout__.fileno())
except (NameError, OSError): except (AttributeError, OSError):
size = os.terminal_size(fallback) size = os.terminal_size(fallback)
if columns <= 0: if columns <= 0:
columns = size.columns columns = size.columns
......
...@@ -1837,6 +1837,8 @@ class TermsizeTests(unittest.TestCase): ...@@ -1837,6 +1837,8 @@ class TermsizeTests(unittest.TestCase):
self.assertEqual(size.lines, 888) self.assertEqual(size.lines, 888)
@unittest.skipUnless(os.isatty(sys.__stdout__.fileno()), "not on tty") @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): def test_stty_match(self):
"""Check if stty returns the same results ignoring env """Check if stty returns the same results ignoring env
......
...@@ -90,6 +90,7 @@ Matthew Barnett ...@@ -90,6 +90,7 @@ Matthew Barnett
Richard Barran Richard Barran
Cesar Eduardo Barros Cesar Eduardo Barros
Des Barry Des Barry
Emanuel Barry
Ulf Bartelt Ulf Bartelt
Campbell Barton Campbell Barton
Don Bashford Don Bashford
......
...@@ -107,6 +107,10 @@ Core and Builtins ...@@ -107,6 +107,10 @@ Core and Builtins
Library 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 - Issue #24838: tarfile's ustar and gnu formats now correctly calculate name
and link field limits for multibyte character encodings like utf-8. and link field limits for multibyte character encodings like utf-8.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment