##// END OF EJS Templates
Catch errors in querying readline which occur with pyreadline.
Thomas Kluyver -
Show More
@@ -144,23 +144,29 b' class ReadlineNoRecord(object):'
144 144
145 145 def __enter__(self):
146 146 if self._nested_level == 0:
147 self.orig_length = self.current_length()
148 self.readline_tail = self.get_readline_tail()
147 try:
148 self.orig_length = self.current_length()
149 self.readline_tail = self.get_readline_tail()
150 except (AttributeError, IndexError): # Can fail with pyreadline
151 self.orig_length, self.readline_tail = 999999, []
149 152 self._nested_level += 1
150 153
151 154 def __exit__(self, type, value, traceback):
152 155 self._nested_level -= 1
153 156 if self._nested_level == 0:
154 157 # Try clipping the end if it's got longer
155 e = self.current_length() - self.orig_length
156 if e > 0:
157 for _ in range(e):
158 self.shell.readline.remove_history_item(self.orig_length)
159
160 # If it still doesn't match, just reload readline history.
161 if self.current_length() != self.orig_length \
162 or self.get_readline_tail() != self.readline_tail:
163 self.shell.refill_readline_hist()
158 try:
159 e = self.current_length() - self.orig_length
160 if e > 0:
161 for _ in range(e):
162 self.shell.readline.remove_history_item(self.orig_length)
163
164 # If it still doesn't match, just reload readline history.
165 if self.current_length() != self.orig_length \
166 or self.get_readline_tail() != self.readline_tail:
167 self.shell.refill_readline_hist()
168 except (AttributeError, IndexError):
169 pass
164 170 # Returning False will cause exceptions to propagate
165 171 return False
166 172
General Comments 0
You need to be logged in to leave comments. Login now