|
4 | 4 | import sys |
5 | 5 | import threading |
6 | 6 |
|
7 | | -from importlib import import_module |
8 | 7 | from test import support |
9 | 8 | from test.support import os_helper |
10 | 9 |
|
11 | 10 | from .utils import print_warning |
12 | 11 |
|
| 12 | +# Import termios to save and restore the tty. This is only available on |
| 13 | +# Unix, and it's fine if the module can't be found. |
| 14 | +try: |
| 15 | + import termios |
| 16 | +except ModuleNotFoundError: |
| 17 | + pass |
| 18 | + |
13 | 19 |
|
14 | 20 | class SkipTestEnvironment(Exception): |
15 | 21 | pass |
@@ -73,16 +79,11 @@ def get_module(self, name): |
73 | 79 | # function for restore() methods |
74 | 80 | return sys.modules[name] |
75 | 81 |
|
76 | | - def try_get_module(self, name, *, demand=False): |
| 82 | + def try_get_module(self, name): |
77 | 83 | # function for get() methods |
78 | 84 | try: |
79 | 85 | return self.get_module(name) |
80 | 86 | except KeyError: |
81 | | - if demand: |
82 | | - try: |
83 | | - return import_module(name) |
84 | | - except ModuleNotFoundError: |
85 | | - pass |
86 | 87 | raise SkipTestEnvironment |
87 | 88 |
|
88 | 89 | def get_urllib_requests__url_tempfiles(self): |
@@ -300,13 +301,12 @@ def restore_warnings_showwarning(self, fxn): |
300 | 301 | warnings.showwarning = fxn |
301 | 302 |
|
302 | 303 | def get_stty_echo(self): |
303 | | - termios = self.try_get_module('termios', demand=True) |
| 304 | + termios = self.try_get_module('termios') |
304 | 305 | if not os.isatty(fd := sys.__stdin__.fileno()): |
305 | 306 | return None |
306 | 307 | attrs = termios.tcgetattr(fd) |
307 | 308 | lflags = attrs[3] |
308 | 309 | return bool(lflags & termios.ECHO) |
309 | | - |
310 | 310 | def restore_stty_echo(self, echo): |
311 | 311 | termios = self.get_module('termios') |
312 | 312 | attrs = termios.tcgetattr(fd := sys.__stdin__.fileno()) |
|
0 commit comments