Skip to content

Commit 7a92ccc

Browse files
committed
- When the history file contains non-utf8 character sequences,
don't crash but just replace them with the "unknown" unicode char. - When writing out text to the terminal, use "?" instead of crashing when the text cannot be encoded.
1 parent c2f81b1 commit 7a92ccc

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

pyrepl/readline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ def _histline(self, line):
235235
try:
236236
return unicode(line, ENCODING)
237237
except UnicodeDecodeError: # bah, silently fall back...
238-
return unicode(line, 'utf-8')
238+
return unicode(line, 'utf-8', 'replace')
239239

240240
def get_history_length(self):
241241
return self.saved_history_length

pyrepl/unix_console.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ def flushoutput(self):
477477
if iscode:
478478
self.__tputs(text)
479479
else:
480-
os.write(self.output_fd, text.encode(self.encoding))
480+
os.write(self.output_fd, text.encode(self.encoding, 'replace'))
481481
del self.__buffer[:]
482482

483483
def __tputs(self, fmt, prog=delayprog):

0 commit comments

Comments
 (0)