MCPcopy Index your code
hub / github.com/python/cpython / read_history_file

Method read_history_file

Lib/_pyrepl/readline.py:429–456  ·  view source on GitHub ↗
(self, filename: str = gethistoryfile())

Source from the content-addressed store, hash-verified

427 return len(self.get_reader().history)
428
429 def read_history_file(self, filename: str = gethistoryfile()) -> None:
430 # multiline extension (really a hack) for the end of lines that
431 # are actually continuations inside a single multiline_input()
432 # history item: we use \r\n instead of just \n. If the history
433 # file is passed to GNU readline, the extra \r are just ignored.
434 history = self.get_reader().history
435
436 with open(os.path.expanduser(filename), 'rb') as f:
437 is_editline = f.readline().startswith(b"_HiStOrY_V2_")
438 if is_editline:
439 encoding = "unicode-escape"
440 else:
441 f.seek(0)
442 encoding = "utf-8"
443
444 lines = [line.decode(encoding, errors='replace') for line in f.read().split(b'\n')]
445 buffer = []
446 for line in lines:
447 if line.endswith("\r"):
448 buffer.append(line+'\n')
449 else:
450 line = self._histline(line)
451 if buffer:
452 line = self._histline("".join(buffer).replace("\r", "") + line)
453 del buffer[:]
454 if line:
455 history.append(line)
456 self.set_history_length(self.get_current_history_length())
457
458 def write_history_file(self, filename: str = gethistoryfile()) -> None:
459 maxlength = self.saved_history_length

Calls 15

get_readerMethod · 0.95
_histlineMethod · 0.95
set_history_lengthMethod · 0.95
gethistoryfileFunction · 0.90
expanduserMethod · 0.80
openFunction · 0.50
startswithMethod · 0.45
readlineMethod · 0.45
seekMethod · 0.45
decodeMethod · 0.45
splitMethod · 0.45