##// END OF EJS Templates
Improve history API docs
Thomas Kluyver -
Show More
@@ -29,6 +29,7 b' import threading'
29 # Our own packages
29 # Our own packages
30 from IPython.config.configurable import Configurable
30 from IPython.config.configurable import Configurable
31 from IPython.external.decorator import decorator
31 from IPython.external.decorator import decorator
32 from IPython.utils.decorators import undoc
32 from IPython.utils.path import locate_profile
33 from IPython.utils.path import locate_profile
33 from IPython.utils import py3compat
34 from IPython.utils import py3compat
34 from IPython.utils.traitlets import (
35 from IPython.utils.traitlets import (
@@ -40,6 +41,7 b' from IPython.utils.warn import warn'
40 # Classes and functions
41 # Classes and functions
41 #-----------------------------------------------------------------------------
42 #-----------------------------------------------------------------------------
42
43
44 @undoc
43 class DummyDB(object):
45 class DummyDB(object):
44 """Dummy DB that will act as a black hole for history.
46 """Dummy DB that will act as a black hole for history.
45
47
@@ -59,7 +61,7 b' class DummyDB(object):'
59
61
60 @decorator
62 @decorator
61 def needs_sqlite(f, self, *a, **kw):
63 def needs_sqlite(f, self, *a, **kw):
62 """return an empty list in the absence of sqlite"""
64 """Decorator: return an empty list in the absence of sqlite."""
63 if sqlite3 is None or not self.enabled:
65 if sqlite3 is None or not self.enabled:
64 return []
66 return []
65 else:
67 else:
@@ -69,6 +71,7 b' def needs_sqlite(f, self, *a, **kw):'
69 if sqlite3 is not None:
71 if sqlite3 is not None:
70 DatabaseError = sqlite3.DatabaseError
72 DatabaseError = sqlite3.DatabaseError
71 else:
73 else:
74 @undoc
72 class DatabaseError(Exception):
75 class DatabaseError(Exception):
73 "Dummy exception when sqlite could not be imported. Should never occur."
76 "Dummy exception when sqlite could not be imported. Should never occur."
74
77
@@ -159,7 +162,7 b' class HistoryAccessor(Configurable):'
159 hist_file : str
162 hist_file : str
160 Path to an SQLite history database stored by IPython. If specified,
163 Path to an SQLite history database stored by IPython. If specified,
161 hist_file overrides profile.
164 hist_file overrides profile.
162 config :
165 config : :class:`~IPython.config.loader.Config`
163 Config object. hist_file can also be set through this.
166 Config object. hist_file can also be set through this.
164 """
167 """
165 # We need a pointer back to the shell for various tasks.
168 # We need a pointer back to the shell for various tasks.
@@ -254,8 +257,8 b' class HistoryAccessor(Configurable):'
254
257
255 @needs_sqlite
258 @needs_sqlite
256 @catch_corrupt_db
259 @catch_corrupt_db
257 def get_session_info(self, session=0):
260 def get_session_info(self, session):
258 """get info about a session
261 """Get info about a session.
259
262
260 Parameters
263 Parameters
261 ----------
264 ----------
@@ -268,13 +271,13 b' class HistoryAccessor(Configurable):'
268
271
269 session_id : int
272 session_id : int
270 Session ID number
273 Session ID number
271 start : datetime
274 start : datetime
272 Timestamp for the start of the session.
275 Timestamp for the start of the session.
273 end : datetime
276 end : datetime
274 Timestamp for the end of the session, or None if IPython crashed.
277 Timestamp for the end of the session, or None if IPython crashed.
275 num_cmds : int
278 num_cmds : int
276 Number of commands run, or None if IPython crashed.
279 Number of commands run, or None if IPython crashed.
277 remark : unicode
280 remark : unicode
278 A manually set description.
281 A manually set description.
279 """
282 """
280 query = "SELECT * from sessions where session == ?"
283 query = "SELECT * from sessions where session == ?"
@@ -383,9 +386,10 b' class HistoryAccessor(Configurable):'
383
386
384 Returns
387 Returns
385 -------
388 -------
386 An iterator over the desired lines. Each line is a 3-tuple, either
389 entries
387 (session, line, input) if output is False, or
390 An iterator over the desired lines. Each line is a 3-tuple, either
388 (session, line, (input, output)) if output is True.
391 (session, line, input) if output is False, or
392 (session, line, (input, output)) if output is True.
389 """
393 """
390 if stop:
394 if stop:
391 lineclause = "line >= ? AND line < ?"
395 lineclause = "line >= ? AND line < ?"
@@ -545,27 +549,27 b' class HistoryManager(HistoryAccessor):'
545 # Methods for retrieving history
549 # Methods for retrieving history
546 # ------------------------------
550 # ------------------------------
547 def get_session_info(self, session=0):
551 def get_session_info(self, session=0):
548 """get info about a session
552 """Get info about a session.
549
553
550 Parameters
554 Parameters
551 ----------
555 ----------
552
556
553 session : int
557 session : int
554 Session number to retrieve. The current session is 0, and negative
558 Session number to retrieve. The current session is 0, and negative
555 numbers count back from current session, so -1 is previous session.
559 numbers count back from current session, so -1 is the previous session.
556
560
557 Returns
561 Returns
558 -------
562 -------
559
563
560 session_id : int
564 session_id : int
561 Session ID number
565 Session ID number
562 start : datetime
566 start : datetime
563 Timestamp for the start of the session.
567 Timestamp for the start of the session.
564 end : datetime
568 end : datetime
565 Timestamp for the end of the session, or None if IPython crashed.
569 Timestamp for the end of the session, or None if IPython crashed.
566 num_cmds : int
570 num_cmds : int
567 Number of commands run, or None if IPython crashed.
571 Number of commands run, or None if IPython crashed.
568 remark : unicode
572 remark : unicode
569 A manually set description.
573 A manually set description.
570 """
574 """
571 if session <= 0:
575 if session <= 0:
@@ -616,9 +620,10 b' class HistoryManager(HistoryAccessor):'
616
620
617 Returns
621 Returns
618 -------
622 -------
619 An iterator over the desired lines. Each line is a 3-tuple, either
623 entries
620 (session, line, input) if output is False, or
624 An iterator over the desired lines. Each line is a 3-tuple, either
621 (session, line, (input, output)) if output is True.
625 (session, line, input) if output is False, or
626 (session, line, (input, output)) if output is True.
622 """
627 """
623 if session <= 0:
628 if session <= 0:
624 session += self.session_number
629 session += self.session_number
@@ -632,7 +637,7 b' class HistoryManager(HistoryAccessor):'
632 ## ----------------------------
637 ## ----------------------------
633 def store_inputs(self, line_num, source, source_raw=None):
638 def store_inputs(self, line_num, source, source_raw=None):
634 """Store source and raw input in history and create input cache
639 """Store source and raw input in history and create input cache
635 variables _i*.
640 variables ``_i*``.
636
641
637 Parameters
642 Parameters
638 ----------
643 ----------
@@ -803,7 +808,7 b' def extract_hist_ranges(ranges_str):'
803
808
804 Examples
809 Examples
805 --------
810 --------
806 list(extract_input_ranges("~8/5-~7/4 2"))
811 >>> list(extract_input_ranges("~8/5-~7/4 2"))
807 [(-8, 5, None), (-7, 1, 4), (0, 2, 3)]
812 [(-8, 5, None), (-7, 1, 4), (0, 2, 3)]
808 """
813 """
809 for range_str in ranges_str.split():
814 for range_str in ranges_str.split():
General Comments 0
You need to be logged in to leave comments. Login now