From 338b5bd0f6ee0d728a8bb04eca9a58538359945a Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Tue, 30 Apr 2019 18:59:34 +0200 Subject: [PATCH] more defensive --- pyrepl/reader.py | 2 +- pyrepl/unix_console.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/pyrepl/reader.py b/pyrepl/reader.py index f9869e4..587e3b1 100644 --- a/pyrepl/reader.py +++ b/pyrepl/reader.py @@ -478,8 +478,8 @@ def prepare(self): """Get ready to run. Call restore when finished. You must not write to the console in between the calls to prepare and restore.""" - self.console.prepare() try: + self.console.prepare() self.arg = None self.screeninfo = [] self.finished = 0 diff --git a/pyrepl/unix_console.py b/pyrepl/unix_console.py index 86f879e..99aeb8c 100644 --- a/pyrepl/unix_console.py +++ b/pyrepl/unix_console.py @@ -359,6 +359,7 @@ def prepare(self): except termios.error: # (25, 'Inappropriate ioctl for device') # assert not os.fdopen(self.input_fd).isatty() raise EOFError + self._prepared = True raw = self.__svtermstate.copy() raw.iflag |= termios.ICRNL raw.iflag &= ~(termios.BRKINT | termios.INPCK | @@ -390,6 +391,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)