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