##// END OF EJS Templates
Tidy up store_inputs
Thomas Kluyver -
Show More
@@ -13,6 +13,7 b''
13 13 from __future__ import print_function
14 14
15 15 # Stdlib imports
16 import fnmatch
16 17 import os
17 18 import sqlite3
18 19
@@ -232,12 +233,15 b' class HistoryManager(object):'
232 233 hist[i] = input_hist[i]
233 234 return hist
234 235
235 def store_inputs(self, source, source_raw=None):
236 def store_inputs(self, line_num, source, source_raw=None):
236 237 """Store source and raw input in history and create input cache
237 238 variables _i*.
238 239
239 240 Parameters
240 241 ----------
242 line_num : int
243 The prompt number of this input.
244
241 245 source : str
242 246 Python input.
243 247
@@ -254,16 +258,15 b' class HistoryManager(object):'
254 258
255 259 self.input_hist_parsed.append(source.rstrip())
256 260 self.input_hist_raw.append(source_raw.rstrip())
257 if self.db_cache_size:
258 self.db_cache.append((self.session_number,
259 self.shell.execution_count, source, source_raw))
261
262 db_row = (self.session_number, line_num, source, source_raw)
263 if self.db_cache_size: # Cache before writing
264 self.db_cache.append(db_row)
260 265 if len(self.db_cache) > self.db_cache_size:
261 266 self.writeout_cache()
262 else: # Instant write
267 else: # Instant write
263 268 with self.db:
264 self.db.execute("INSERT INTO history VALUES (?, ?, ?, ?)",
265 (self.session_number, self.shell.execution_count,
266 source, source_raw))
269 self.db.execute("INSERT INTO history VALUES (?, ?, ?, ?)", db_row)
267 270
268 271 # update the auto _i variables
269 272 self._iii = self._ii
@@ -272,7 +275,7 b' class HistoryManager(object):'
272 275 self._i00 = source_raw
273 276
274 277 # hackish access to user namespace to create _i1,_i2... dynamically
275 new_i = '_i%s' % self.shell.execution_count
278 new_i = '_i%s' % line_num
276 279 to_main = {'_i': self._i,
277 280 '_ii': self._ii,
278 281 '_iii': self._iii,
@@ -2100,7 +2100,7 b' class InteractiveShell(Configurable, Magic):'
2100 2100 ipy_cell = ''.join(blocks)
2101 2101
2102 2102 # Store raw and processed history
2103 self.history_manager.store_inputs(ipy_cell, cell)
2103 self.history_manager.store_inputs(self.execution_count, ipy_cell, cell)
2104 2104
2105 2105 self.logger.log(ipy_cell, cell)
2106 2106
@@ -2390,8 +2390,8 b' class InteractiveShell(Configurable, Magic):'
2390 2390 full_source = '\n'.join(self.buffer)
2391 2391 more = self.run_source(full_source, self.filename)
2392 2392 if not more:
2393 self.history_manager.store_inputs('\n'.join(self.buffer_raw),
2394 full_source)
2393 self.history_manager.store_inputs(self.execution_count,
2394 '\n'.join(self.buffer_raw), full_source)
2395 2395 self.reset_buffer()
2396 2396 self.execution_count += 1
2397 2397 return more
General Comments 0
You need to be logged in to leave comments. Login now