MCPcopy Index your code
hub / github.com/RustPython/RustPython / read_history_file

Method read_history_file

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

Source from the content-addressed store, hash-verified

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

Callers 1

register_readlineFunction · 0.80

Calls 15

get_readerMethod · 0.95
_histlineMethod · 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
readMethod · 0.45
endswithMethod · 0.45

Tested by

no test coverage detected