Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error handling with pyrepl.readline.read_history_file #51

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
25 changes: 13 additions & 12 deletions pyrepl/readline.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,20 +290,21 @@ def read_history_file(self, filename='~/.history'):
# are actually continuations inside a single multiline_input()
# history item: we use \r\n instead of just \n. If the history
# file is passed to GNU readline, the extra \r are just ignored.
import codecs # for py27 compatibility.

history = self.get_reader().history
f = open(os.path.expanduser(filename), 'r')
buffer = []
for line in f:
if line.endswith('\r\n'):
buffer.append(line)
else:
line = self._histline(line)
if buffer:
line = ''.join(buffer).replace('\r', '') + line
del buffer[:]
if line:
history.append(line)
f.close()
with codecs.open(os.path.expanduser(filename), 'r', errors='replace') as f:
for line in f:
if line.endswith('\r\n'):
buffer.append(line)
else:
line = self._histline(line)
if buffer:
line = ''.join(buffer).replace('\r', '') + line
del buffer[:]
if line:
history.append(line)

def write_history_file(self, filename='~/.history'):
maxlength = self.saved_history_length
Expand Down