diff options
author | Min RK <benjaminrk@gmail.com> | 2017-04-28 12:33:45 +0200 |
---|---|---|
committer | Min RK <benjaminrk@gmail.com> | 2017-04-28 12:33:45 +0200 |
commit | 152db3de745bbf56af1777e25abfbc74360e7dba (patch) | |
tree | e585c01b730eff60ad4a5bdd62455fee7d3cf678 | |
parent | 8f1ba73b82a4b4fbe342fef1498cd35362f63982 (diff) | |
download | ptyprocess-152db3de745bbf56af1777e25abfbc74360e7dba.tar.gz |
sys.__stdin__ can be None
raising an AttributeError, which was not among the caught exceptions
-rw-r--r-- | ptyprocess/ptyprocess.py | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/ptyprocess/ptyprocess.py b/ptyprocess/ptyprocess.py index cb3efae..ab2adbc 100644 --- a/ptyprocess/ptyprocess.py +++ b/ptyprocess/ptyprocess.py @@ -60,11 +60,18 @@ def _make_eof_intr(): # inherit EOF and INTR definitions from controlling process. try: from termios import VEOF, VINTR - try: - fd = sys.__stdin__.fileno() - except ValueError: - # ValueError: I/O operation on closed file - fd = sys.__stdout__.fileno() + fd = None + for name in 'stdin', 'stdout': + stream = getattr(sys, '__%s__' % name, None) + if stream is None or not hasattr(stream, 'fileno'): + continue + try: + fd = stream.fileno() + except ValueError: + continue + if fd is None: + # no fd, raise ValueError to fallback on CEOF, CINTR + raise ValueError("No stream has a fileno") intr = ord(termios.tcgetattr(fd)[6][VINTR]) eof = ord(termios.tcgetattr(fd)[6][VEOF]) except (ImportError, OSError, IOError, ValueError, termios.error): |