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.
diff --git a/Lib/shutil.py b/Lib/shutil.py
index 3f4b6bf..7f8edf5 100644
--- 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
index ca1d006..7e41891 100644
--- 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