Store source and raw input in history and create input cache variables ``_i*``. Parameters ---------- line_num : int The prompt number of this input. source : str Python input. source_raw : str, optional If given, t
(
self, line_num: int, source: str, source_raw: Optional[str] = None
)
| 976 | ## Methods for storing history: |
| 977 | ## ---------------------------- |
| 978 | def store_inputs( |
| 979 | self, line_num: int, source: str, source_raw: Optional[str] = None |
| 980 | ) -> None: |
| 981 | """Store source and raw input in history and create input cache |
| 982 | variables ``_i*``. |
| 983 | |
| 984 | Parameters |
| 985 | ---------- |
| 986 | line_num : int |
| 987 | The prompt number of this input. |
| 988 | source : str |
| 989 | Python input. |
| 990 | source_raw : str, optional |
| 991 | If given, this is the raw input without any IPython transformations |
| 992 | applied to it. If not given, ``source`` is used. |
| 993 | """ |
| 994 | if source_raw is None: |
| 995 | source_raw = source |
| 996 | source = source.rstrip("\n") |
| 997 | source_raw = source_raw.rstrip("\n") |
| 998 | |
| 999 | # do not store exit/quit commands |
| 1000 | if self._exit_re.match(source_raw.strip()): |
| 1001 | return |
| 1002 | |
| 1003 | self.input_hist_parsed.append(source) |
| 1004 | self.input_hist_raw.append(source_raw) |
| 1005 | |
| 1006 | with self.db_input_cache_lock: |
| 1007 | self.db_input_cache.append((line_num, source, source_raw)) |
| 1008 | # Trigger to flush cache and write to DB. |
| 1009 | if len(self.db_input_cache) >= self.db_cache_size: |
| 1010 | if self.using_thread: |
| 1011 | self._restart_thread_if_stopped() |
| 1012 | if self.save_flag is not None: |
| 1013 | self.save_flag.set() |
| 1014 | |
| 1015 | # update the auto _i variables |
| 1016 | self._iii = self._ii |
| 1017 | self._ii = self._i |
| 1018 | self._i = self._i00 |
| 1019 | self._i00 = source_raw |
| 1020 | |
| 1021 | # hackish access to user namespace to create _i1,_i2... dynamically |
| 1022 | new_i = "_i%s" % line_num |
| 1023 | to_main = {"_i": self._i, "_ii": self._ii, "_iii": self._iii, new_i: self._i00} |
| 1024 | |
| 1025 | if self.shell is not None: |
| 1026 | self.shell.push(to_main, interactive=False) |
| 1027 | |
| 1028 | def store_output(self, line_num: int) -> None: |
| 1029 | """If database output logging is enabled, this saves all the |