Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

History expects single output per cell, and doesn't use JSON to store…

… them in the database.
  • Loading branch information...
commit 4a9c6fa823e7992c884a6b96b20a4912f044ba4a 1 parent 7a0df63
@takluyver authored
View
4 IPython/core/displayhook.py
@@ -283,8 +283,8 @@ def log_output(self, format_dict):
if self.shell.logger.log_output:
self.shell.logger.log_write(format_dict['text/plain'], 'output')
# This is a defaultdict of lists, so we can always append
- self.shell.history_manager.output_hist_reprs[self.prompt_count]\
- .append(format_dict['text/plain'])
+ self.shell.history_manager.output_hist_reprs[self.prompt_count] = \
+ format_dict['text/plain']
def finish_displayhook(self):
"""Finish up all displayhook activities."""
View
20 IPython/core/history.py
@@ -15,14 +15,11 @@
# Stdlib imports
import atexit
import datetime
-import json
import os
import re
import sqlite3
import threading
-from collections import defaultdict
-
# Our own packages
from IPython.config.configurable import Configurable
import IPython.utils.io
@@ -56,11 +53,10 @@ def _dir_hist_default(self):
return []
# A dict of output history, keyed with ints from the shell's
- # execution count. If there are several outputs from one command,
- # only the last one is stored.
+ # execution count.
output_hist = Dict()
- # Contains all outputs, in lists of reprs.
- output_hist_reprs = Instance(defaultdict, args=(list,))
+ # The text/plain repr of outputs.
+ output_hist_reprs = Dict()
# String holding the path to the history file
hist_file = Unicode(config=True)
@@ -218,9 +214,7 @@ def _run_sql(self, sql, params, raw=True, output=False):
cur = self.db.execute("SELECT session, line, %s FROM %s " %\
(toget, sqlfrom) + sql, params)
if output: # Regroup into 3-tuples, and parse JSON
- loads = lambda out: json.loads(out) if out else None
- return ((ses, lin, (inp, loads(out))) \
- for ses, lin, inp, out in cur)
+ return ((ses, lin, (inp, out)) for ses, lin, inp, out in cur)
return cur
@@ -419,9 +413,9 @@ def store_output(self, line_num):
line_num : int
The line number from which to save outputs
"""
- if (not self.db_log_output) or not self.output_hist_reprs[line_num]:
+ if (not self.db_log_output) or (line_num not in self.output_hist_reprs):
return
- output = json.dumps(self.output_hist_reprs[line_num])
+ output = self.output_hist_reprs[line_num]
with self.db_output_cache_lock:
self.db_output_cache.append((line_num, output))
@@ -696,7 +690,7 @@ def _format_lineno(session, line):
inline = "\n... ".join(inline.splitlines()) + "\n..."
print(inline, file=outfile)
if get_output and output:
- print("\n".join(output), file=outfile)
+ print(output, file=outfile)
if close_at_end:
outfile.close()
View
6 IPython/core/tests/test_history.py
@@ -33,7 +33,7 @@ def test_history():
ip.history_manager.db_log_output = True
# Doesn't match the input, but we'll just check it's stored.
- ip.history_manager.output_hist_reprs[3].append("spam")
+ ip.history_manager.output_hist_reprs[3] = "spam"
ip.history_manager.store_output(3)
nt.assert_equal(ip.history_manager.input_hist_raw, [''] + hist)
@@ -53,7 +53,7 @@ def test_history():
# Check get_hist_tail
gothist = ip.history_manager.get_tail(4, output=True,
include_latest=True)
- expected = [(1, 3, (hist[-1], ["spam"])),
+ expected = [(1, 3, (hist[-1], "spam")),
(2, 1, (newcmds[0], None)),
(2, 2, (newcmds[1], None)),
(2, 3, (newcmds[2], None)),]
@@ -68,7 +68,7 @@ def test_history():
gothist = ip.history_manager.search("*test*")
nt.assert_equal(list(gothist), [(1,2,hist[1])] )
gothist = ip.history_manager.search("b*", output=True)
- nt.assert_equal(list(gothist), [(1,3,(hist[2],["spam"]))] )
+ nt.assert_equal(list(gothist), [(1,3,(hist[2],"spam"))] )
# Cross testing: check that magic %save can get previous session.
testfilename = os.path.realpath(os.path.join(tmpdir, "test.py"))

0 comments on commit 4a9c6fa

Please sign in to comment.
Something went wrong with that request. Please try again.