Show More
@@ -909,7 +909,7 b' def magic_rep(self, arg):' | |||
|
909 | 909 | self.shell.set_next_input(str(self.shell.user_ns["_"])) |
|
910 | 910 | return |
|
911 | 911 | # Get history range |
|
912 | histlines = self.history_manager.get_range_by_str(arg) | |
|
912 | histlines = self.shell.history_manager.get_range_by_str(arg) | |
|
913 | 913 | cmd = "\n".join(x[2] for x in histlines) |
|
914 | 914 | if cmd: |
|
915 | 915 | self.shell.set_next_input(cmd.rstrip()) |
@@ -918,7 +918,7 b' def magic_rep(self, arg):' | |||
|
918 | 918 | try: # Variable in user namespace |
|
919 | 919 | cmd = str(eval(arg, self.shell.user_ns)) |
|
920 | 920 | except Exception: # Search for term in history |
|
921 | histlines = self.history_manager.search("*"+arg+"*") | |
|
921 | histlines = self.shell.history_manager.search("*"+arg+"*") | |
|
922 | 922 | for h in reversed([x[2] for x in histlines]): |
|
923 | 923 | if 'rep' in h: |
|
924 | 924 | continue |
@@ -945,10 +945,10 b" def magic_rerun(self, parameter_s=''):" | |||
|
945 | 945 | opts, args = self.parse_options(parameter_s, 'l:g:', mode='string') |
|
946 | 946 | if "l" in opts: # Last n lines |
|
947 | 947 | n = int(opts['l']) |
|
948 | hist = self.history_manager.get_tail(n) | |
|
948 | hist = self.shell.history_manager.get_tail(n) | |
|
949 | 949 | elif "g" in opts: # Search |
|
950 | 950 | p = "*"+opts['g']+"*" |
|
951 | hist = list(self.history_manager.search(p)) | |
|
951 | hist = list(self.shell.history_manager.search(p)) | |
|
952 | 952 | for l in reversed(hist): |
|
953 | 953 | if "rerun" not in l[2]: |
|
954 | 954 | hist = [l] # The last match which isn't a %rerun |
@@ -956,9 +956,9 b" def magic_rerun(self, parameter_s=''):" | |||
|
956 | 956 | else: |
|
957 | 957 | hist = [] # No matches except %rerun |
|
958 | 958 | elif args: # Specify history ranges |
|
959 | hist = self.history_manager.get_range_by_str(args) | |
|
959 | hist = self.shell.history_manager.get_range_by_str(args) | |
|
960 | 960 | else: # Last line |
|
961 | hist = self.history_manager.get_tail(1) | |
|
961 | hist = self.shell.history_manager.get_tail(1) | |
|
962 | 962 | hist = [x[2] for x in hist] |
|
963 | 963 | if not hist: |
|
964 | 964 | print("No lines in history match specification") |
@@ -967,7 +967,7 b" def magic_rerun(self, parameter_s=''):" | |||
|
967 | 967 | print("=== Executing: ===") |
|
968 | 968 | print(histlines) |
|
969 | 969 | print("=== Output: ===") |
|
970 | self.run_cell("\n".join(hist), store_history=False) | |
|
970 | self.shell.run_cell("\n".join(hist), store_history=False) | |
|
971 | 971 | |
|
972 | 972 | |
|
973 | 973 | def init_ipython(ip): |
@@ -171,8 +171,8 b' python-profiler package from non-free.""")' | |||
|
171 | 171 | inst_bound_magic = lambda fn: fn.startswith('magic_') and \ |
|
172 | 172 | callable(self.__class__.__dict__[fn]) |
|
173 | 173 | magics = filter(class_magic,Magic.__dict__.keys()) + \ |
|
174 | filter(inst_magic,self.__dict__.keys()) + \ | |
|
175 | filter(inst_bound_magic,self.__class__.__dict__.keys()) | |
|
174 | filter(inst_magic, self.__dict__.keys()) + \ | |
|
175 | filter(inst_bound_magic, self.__class__.__dict__.keys()) | |
|
176 | 176 | out = [] |
|
177 | 177 | for fn in set(magics): |
|
178 | 178 | out.append(fn.replace('magic_','',1)) |
@@ -337,7 +337,7 b' python-profiler package from non-free.""")' | |||
|
337 | 337 | magic_docs = [] |
|
338 | 338 | for fname in self.lsmagic(): |
|
339 | 339 | mname = 'magic_' + fname |
|
340 | for space in (Magic,self,self.__class__): | |
|
340 | for space in (Magic, self, self.__class__): | |
|
341 | 341 | try: |
|
342 | 342 | fn = space.__dict__[mname] |
|
343 | 343 | except KeyError: |
@@ -1035,17 +1035,17 b' Currently the magic system has the following functions:\\n"""' | |||
|
1035 | 1035 | |
|
1036 | 1036 | # reset in/out/dhist/array: previously extensinions/clearcmd.py |
|
1037 | 1037 | ip = self.shell |
|
1038 | user_ns = self.user_ns # local lookup, heavily used | |
|
1038 | user_ns = self.shell.user_ns # local lookup, heavily used | |
|
1039 | 1039 | |
|
1040 | 1040 | for target in args: |
|
1041 | 1041 | target = target.lower() # make matches case insensitive |
|
1042 | 1042 | if target == 'out': |
|
1043 | 1043 | print "Flushing output cache (%d entries)" % len(user_ns['_oh']) |
|
1044 | self.displayhook.flush() | |
|
1044 | self.shell.displayhook.flush() | |
|
1045 | 1045 | |
|
1046 | 1046 | elif target == 'in': |
|
1047 | 1047 | print "Flushing input history" |
|
1048 | pc = self.displayhook.prompt_count + 1 | |
|
1048 | pc = self.shell.displayhook.prompt_count + 1 | |
|
1049 | 1049 | for n in range(1, pc): |
|
1050 | 1050 | key = '_i'+repr(n) |
|
1051 | 1051 | user_ns.pop(key,None) |
@@ -2630,7 +2630,7 b' Currently the magic system has the following functions:\\n"""' | |||
|
2630 | 2630 | self.shell.run_cell(file_read(filename), |
|
2631 | 2631 | store_history=False) |
|
2632 | 2632 | else: |
|
2633 | self.shell.safe_execfile(filename,self.shell.user_ns, | |
|
2633 | self.shell.safe_execfile(filename, self.shell.user_ns, | |
|
2634 | 2634 | self.shell.user_ns) |
|
2635 | 2635 | |
|
2636 | 2636 | if is_temp: |
@@ -3804,7 +3804,8 b' Defaulting color scheme to \'NoColor\'"""' | |||
|
3804 | 3804 | # some IPython objects are Configurable, but do not yet have |
|
3805 | 3805 | # any configurable traits. Exclude them from the effects of |
|
3806 | 3806 | # this magic, as their presence is just noise: |
|
3807 |
configurables = [ c for c in self.configurables |
|
|
3807 | configurables = [ c for c in self.shell.configurables | |
|
3808 | if c.__class__.class_traits(config=True) ] | |
|
3808 | 3809 | classnames = [ c.__class__.__name__ for c in configurables ] |
|
3809 | 3810 | |
|
3810 | 3811 | line = s.strip() |
@@ -3832,7 +3833,7 b' Defaulting color scheme to \'NoColor\'"""' | |||
|
3832 | 3833 | # leave quotes on args when splitting, because we want |
|
3833 | 3834 | # unquoted args to eval in user_ns |
|
3834 | 3835 | cfg = Config() |
|
3835 | exec "cfg."+line in locals(), self.user_ns | |
|
3836 | exec "cfg."+line in locals(), self.shell.user_ns | |
|
3836 | 3837 | |
|
3837 | 3838 | for configurable in configurables: |
|
3838 | 3839 | try: |
@@ -807,7 +807,7 b' class AutoHandler(PrefilterHandler):' | |||
|
807 | 807 | pre = line_info.pre |
|
808 | 808 | esc = line_info.esc |
|
809 | 809 | continue_prompt = line_info.continue_prompt |
|
810 | obj = line_info.ofind(self)['obj'] | |
|
810 | obj = line_info.ofind(self.shell)['obj'] | |
|
811 | 811 | #print 'pre <%s> ifun <%s> rest <%s>' % (pre,ifun,the_rest) # dbg |
|
812 | 812 | |
|
813 | 813 | # This should only be active for single-line input! |
@@ -49,6 +49,7 b' line_split = re.compile("""' | |||
|
49 | 49 | (.*?$|$) # rest of line |
|
50 | 50 | """, re.VERBOSE) |
|
51 | 51 | |
|
52 | ||
|
52 | 53 | def split_user_input(line, pattern=None): |
|
53 | 54 | """Split user input into initial whitespace, escape character, function part |
|
54 | 55 | and the rest. |
@@ -76,6 +77,7 b' def split_user_input(line, pattern=None):' | |||
|
76 | 77 | #print 'pre <%s> ifun <%s> rest <%s>' % (pre,ifun.strip(),the_rest) # dbg |
|
77 | 78 | return pre, esc or '', ifun.strip(), the_rest.lstrip() |
|
78 | 79 | |
|
80 | ||
|
79 | 81 | class LineInfo(object): |
|
80 | 82 | """A single line of input and associated info. |
|
81 | 83 | |
@@ -122,7 +124,7 b' class LineInfo(object):' | |||
|
122 | 124 | """Do a full, attribute-walking lookup of the ifun in the various |
|
123 | 125 | namespaces for the given IPython InteractiveShell instance. |
|
124 | 126 | |
|
125 | Return a dict with keys: found,obj,ospace,ismagic | |
|
127 | Return a dict with keys: {found, obj, ospace, ismagic} | |
|
126 | 128 | |
|
127 | 129 | Note: can cause state changes because of calling getattr, but should |
|
128 | 130 | only be run if autocall is on and if the line hasn't matched any |
General Comments 0
You need to be logged in to leave comments.
Login now