##// END OF EJS Templates
Fix history (was accessing directly shell methods)
Fernando Perez -
Show More
@@ -54,6 +54,7 b' class DummyDB(object):'
54 54 def __exit__(self, *args, **kwargs):
55 55 pass
56 56
57
57 58 @decorator
58 59 def needs_sqlite(f,*a,**kw):
59 60 """return an empty list in the absence of sqlite"""
@@ -62,6 +63,7 b' def needs_sqlite(f,*a,**kw):'
62 63 else:
63 64 return f(*a,**kw)
64 65
66
65 67 class HistoryAccessor(Configurable):
66 68 """Access the history database without adding to it.
67 69
@@ -84,7 +86,6 b' class HistoryAccessor(Configurable):'
84 86
85 87 """)
86 88
87
88 89 # The SQLite database
89 90 if sqlite3:
90 91 db = Instance(sqlite3.Connection)
@@ -676,6 +677,7 b' range_re = re.compile(r"""'
676 677 (?P<end>\d+))?
677 678 $""", re.VERBOSE)
678 679
680
679 681 def extract_hist_ranges(ranges_str):
680 682 """Turn a string of history ranges into 3-tuples of (session, start, stop).
681 683
@@ -708,12 +710,14 b' def extract_hist_ranges(ranges_str):'
708 710 yield (sess, 1, None)
709 711 yield (endsess, 1, end)
710 712
713
711 714 def _format_lineno(session, line):
712 715 """Helper function to format line numbers properly."""
713 716 if session == 0:
714 717 return str(line)
715 718 return "%s#%s" % (session, line)
716 719
720
717 721 @skip_doctest
718 722 def magic_history(self, parameter_s = ''):
719 723 """Print input history (_i<n> variables), with most recent last.
@@ -902,13 +906,13 b' def magic_rep(self, arg):'
902 906 placed at the next input prompt.
903 907 """
904 908 if not arg: # Last output
905 self.set_next_input(str(self.shell.user_ns["_"]))
909 self.shell.set_next_input(str(self.shell.user_ns["_"]))
906 910 return
907 911 # Get history range
908 912 histlines = self.history_manager.get_range_by_str(arg)
909 913 cmd = "\n".join(x[2] for x in histlines)
910 914 if cmd:
911 self.set_next_input(cmd.rstrip())
915 self.shell.set_next_input(cmd.rstrip())
912 916 return
913 917
914 918 try: # Variable in user namespace
@@ -918,10 +922,10 b' def magic_rep(self, arg):'
918 922 for h in reversed([x[2] for x in histlines]):
919 923 if 'rep' in h:
920 924 continue
921 self.set_next_input(h.rstrip())
925 self.shell.set_next_input(h.rstrip())
922 926 return
923 927 else:
924 self.set_next_input(cmd.rstrip())
928 self.shell.set_next_input(cmd.rstrip())
925 929 print("Couldn't evaluate or find in history:", arg)
926 930
927 931
@@ -2053,7 +2053,7 b' class InteractiveShell(SingletonConfigurable):'
2053 2053
2054 2054 ip.define_magic('foo',foo_impl)
2055 2055 """
2056 im = types.MethodType(func,self)
2056 im = types.MethodType(func, self._magic)
2057 2057 old = self.find_magic(magic_name)
2058 2058 setattr(self._magic, 'magic_' + magic_name, im)
2059 2059 return old
General Comments 0
You need to be logged in to leave comments. Login now