Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion pyrepl/unix_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,11 @@ def move_cursor(self, x, y):

def prepare(self):
# per-readline preparations:
self.__svtermstate = tcgetattr(self.input_fd)
try:
self.__svtermstate = tcgetattr(self.input_fd)
except termios.error as exc:
raise EOFError("could not prepare fd %d: %s" % (self.input_fd, exc))
self._prepared = True
raw = self.__svtermstate.copy()
raw.iflag |= termios.ICRNL
raw.iflag &= ~(termios.BRKINT | termios.INPCK |
Expand Down Expand Up @@ -386,6 +390,9 @@ def prepare(self):
pass

def restore(self):
if not hasattr(self, '_prepared'):
return
del self._prepared
self.__maybe_write_code(self._rmkx)
self.flushoutput()
tcsetattr(self.input_fd, termios.TCSADRAIN, self.__svtermstate)
Expand Down
12 changes: 12 additions & 0 deletions testing/test_unix_console.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import pytest


def test_eoferror():
from pyrepl.unix_console import UnixConsole

console = UnixConsole(f_in=99)
with pytest.raises(
EOFError,
match="^could not prepare fd 99: .*Bad file descriptor"
):
console.prepare()