Show More
@@ -283,8 +283,8 b' class DisplayHook(Configurable):' | |||||
283 | if self.shell.logger.log_output: |
|
283 | if self.shell.logger.log_output: | |
284 | self.shell.logger.log_write(format_dict['text/plain'], 'output') |
|
284 | self.shell.logger.log_write(format_dict['text/plain'], 'output') | |
285 | # This is a defaultdict of lists, so we can always append |
|
285 | # This is a defaultdict of lists, so we can always append | |
286 | self.shell.history_manager.output_hist_reprs[self.prompt_count]\ |
|
286 | self.shell.history_manager.output_hist_reprs[self.prompt_count] = \ | |
287 |
|
|
287 | format_dict['text/plain'] | |
288 |
|
288 | |||
289 | def finish_displayhook(self): |
|
289 | def finish_displayhook(self): | |
290 | """Finish up all displayhook activities.""" |
|
290 | """Finish up all displayhook activities.""" |
@@ -15,14 +15,11 b' from __future__ import print_function' | |||||
15 | # Stdlib imports |
|
15 | # Stdlib imports | |
16 | import atexit |
|
16 | import atexit | |
17 | import datetime |
|
17 | import datetime | |
18 | import json |
|
|||
19 | import os |
|
18 | import os | |
20 | import re |
|
19 | import re | |
21 | import sqlite3 |
|
20 | import sqlite3 | |
22 | import threading |
|
21 | import threading | |
23 |
|
22 | |||
24 | from collections import defaultdict |
|
|||
25 |
|
||||
26 | # Our own packages |
|
23 | # Our own packages | |
27 | from IPython.config.configurable import Configurable |
|
24 | from IPython.config.configurable import Configurable | |
28 | import IPython.utils.io |
|
25 | import IPython.utils.io | |
@@ -56,11 +53,10 b' class HistoryManager(Configurable):' | |||||
56 | return [] |
|
53 | return [] | |
57 |
|
54 | |||
58 | # A dict of output history, keyed with ints from the shell's |
|
55 | # A dict of output history, keyed with ints from the shell's | |
59 | # execution count. If there are several outputs from one command, |
|
56 | # execution count. | |
60 | # only the last one is stored. |
|
|||
61 | output_hist = Dict() |
|
57 | output_hist = Dict() | |
62 | # Contains all outputs, in lists of reprs. |
|
58 | # The text/plain repr of outputs. | |
63 |
output_hist_reprs = |
|
59 | output_hist_reprs = Dict() | |
64 |
|
60 | |||
65 | # String holding the path to the history file |
|
61 | # String holding the path to the history file | |
66 | hist_file = Unicode(config=True) |
|
62 | hist_file = Unicode(config=True) | |
@@ -218,9 +214,7 b' class HistoryManager(Configurable):' | |||||
218 | cur = self.db.execute("SELECT session, line, %s FROM %s " %\ |
|
214 | cur = self.db.execute("SELECT session, line, %s FROM %s " %\ | |
219 | (toget, sqlfrom) + sql, params) |
|
215 | (toget, sqlfrom) + sql, params) | |
220 | if output: # Regroup into 3-tuples, and parse JSON |
|
216 | if output: # Regroup into 3-tuples, and parse JSON | |
221 | loads = lambda out: json.loads(out) if out else None |
|
217 | return ((ses, lin, (inp, out)) for ses, lin, inp, out in cur) | |
222 | return ((ses, lin, (inp, loads(out))) \ |
|
|||
223 | for ses, lin, inp, out in cur) |
|
|||
224 | return cur |
|
218 | return cur | |
225 |
|
219 | |||
226 |
|
220 | |||
@@ -419,9 +413,9 b' class HistoryManager(Configurable):' | |||||
419 | line_num : int |
|
413 | line_num : int | |
420 | The line number from which to save outputs |
|
414 | The line number from which to save outputs | |
421 | """ |
|
415 | """ | |
422 |
if (not self.db_log_output) or not self.output_hist_reprs |
|
416 | if (not self.db_log_output) or (line_num not in self.output_hist_reprs): | |
423 | return |
|
417 | return | |
424 |
output = |
|
418 | output = self.output_hist_reprs[line_num] | |
425 |
|
419 | |||
426 | with self.db_output_cache_lock: |
|
420 | with self.db_output_cache_lock: | |
427 | self.db_output_cache.append((line_num, output)) |
|
421 | self.db_output_cache.append((line_num, output)) | |
@@ -696,7 +690,7 b" def magic_history(self, parameter_s = ''):" | |||||
696 | inline = "\n... ".join(inline.splitlines()) + "\n..." |
|
690 | inline = "\n... ".join(inline.splitlines()) + "\n..." | |
697 | print(inline, file=outfile) |
|
691 | print(inline, file=outfile) | |
698 | if get_output and output: |
|
692 | if get_output and output: | |
699 |
print( |
|
693 | print(output, file=outfile) | |
700 |
|
694 | |||
701 | if close_at_end: |
|
695 | if close_at_end: | |
702 | outfile.close() |
|
696 | outfile.close() |
@@ -33,7 +33,7 b' def test_history():' | |||||
33 |
|
33 | |||
34 | ip.history_manager.db_log_output = True |
|
34 | ip.history_manager.db_log_output = True | |
35 | # Doesn't match the input, but we'll just check it's stored. |
|
35 | # Doesn't match the input, but we'll just check it's stored. | |
36 |
ip.history_manager.output_hist_reprs[3] |
|
36 | ip.history_manager.output_hist_reprs[3] = "spam" | |
37 | ip.history_manager.store_output(3) |
|
37 | ip.history_manager.store_output(3) | |
38 |
|
38 | |||
39 | nt.assert_equal(ip.history_manager.input_hist_raw, [''] + hist) |
|
39 | nt.assert_equal(ip.history_manager.input_hist_raw, [''] + hist) | |
@@ -53,7 +53,7 b' def test_history():' | |||||
53 | # Check get_hist_tail |
|
53 | # Check get_hist_tail | |
54 | gothist = ip.history_manager.get_tail(4, output=True, |
|
54 | gothist = ip.history_manager.get_tail(4, output=True, | |
55 | include_latest=True) |
|
55 | include_latest=True) | |
56 |
expected = [(1, 3, (hist[-1], |
|
56 | expected = [(1, 3, (hist[-1], "spam")), | |
57 | (2, 1, (newcmds[0], None)), |
|
57 | (2, 1, (newcmds[0], None)), | |
58 | (2, 2, (newcmds[1], None)), |
|
58 | (2, 2, (newcmds[1], None)), | |
59 | (2, 3, (newcmds[2], None)),] |
|
59 | (2, 3, (newcmds[2], None)),] | |
@@ -68,7 +68,7 b' def test_history():' | |||||
68 | gothist = ip.history_manager.search("*test*") |
|
68 | gothist = ip.history_manager.search("*test*") | |
69 | nt.assert_equal(list(gothist), [(1,2,hist[1])] ) |
|
69 | nt.assert_equal(list(gothist), [(1,2,hist[1])] ) | |
70 | gothist = ip.history_manager.search("b*", output=True) |
|
70 | gothist = ip.history_manager.search("b*", output=True) | |
71 |
nt.assert_equal(list(gothist), [(1,3,(hist[2], |
|
71 | nt.assert_equal(list(gothist), [(1,3,(hist[2],"spam"))] ) | |
72 |
|
72 | |||
73 | # Cross testing: check that magic %save can get previous session. |
|
73 | # Cross testing: check that magic %save can get previous session. | |
74 | testfilename = os.path.realpath(os.path.join(tmpdir, "test.py")) |
|
74 | testfilename = os.path.realpath(os.path.join(tmpdir, "test.py")) |
General Comments 0
You need to be logged in to leave comments.
Login now