Show More
1 | NO CONTENT: modified file |
|
NO CONTENT: modified file |
@@ -36,6 +36,7 b' class HistoryManager(object):' | |||||
36 | def __init__(self, shell): |
|
36 | def __init__(self, shell): | |
37 | """Create a new history manager associated with a shell instance. |
|
37 | """Create a new history manager associated with a shell instance. | |
38 | """ |
|
38 | """ | |
|
39 | # We need a pointer back to the shell for various tasks. | |||
39 | self.shell = shell |
|
40 | self.shell = shell | |
40 |
|
41 | |||
41 | # List of input with multi-line handling. |
|
42 | # List of input with multi-line handling. | |
@@ -64,6 +65,13 b' class HistoryManager(object):' | |||||
64 | # Objects related to shadow history management |
|
65 | # Objects related to shadow history management | |
65 | self._init_shadow_hist() |
|
66 | self._init_shadow_hist() | |
66 |
|
67 | |||
|
68 | # Variables used to store the three last inputs from the user. On each | |||
|
69 | # new history update, we populate the user's namespace with these, | |||
|
70 | # shifted as necessary. | |||
|
71 | self._i00, self._i, self._ii, self._iii = '','','','' | |||
|
72 | ||||
|
73 | # Object is fully initialized, we can now call methods on it. | |||
|
74 | ||||
67 | # Fill the history zero entry, user counter starts at 1 |
|
75 | # Fill the history zero entry, user counter starts at 1 | |
68 | self.store_inputs('\n', '\n') |
|
76 | self.store_inputs('\n', '\n') | |
69 |
|
77 | |||
@@ -158,7 +166,8 b' class HistoryManager(object):' | |||||
158 | return hist |
|
166 | return hist | |
159 |
|
167 | |||
160 | def store_inputs(self, source, source_raw=None): |
|
168 | def store_inputs(self, source, source_raw=None): | |
161 |
"""Store source and raw input in history |
|
169 | """Store source and raw input in history and create input cache | |
|
170 | variables _i*. | |||
162 |
|
171 | |||
163 | Parameters |
|
172 | Parameters | |
164 | ---------- |
|
173 | ---------- | |
@@ -175,6 +184,20 b' class HistoryManager(object):' | |||||
175 | self.input_hist_raw.append(source_raw) |
|
184 | self.input_hist_raw.append(source_raw) | |
176 | self.shadow_hist.add(source) |
|
185 | self.shadow_hist.add(source) | |
177 |
|
186 | |||
|
187 | # update the auto _i variables | |||
|
188 | self._iii = self._ii | |||
|
189 | self._ii = self._i | |||
|
190 | self._i = self._i00 | |||
|
191 | self._i00 = source_raw | |||
|
192 | ||||
|
193 | # hackish access to user namespace to create _i1,_i2... dynamically | |||
|
194 | new_i = '_i%s' % self.shell.execution_count | |||
|
195 | to_main = {'_i': self._i, | |||
|
196 | '_ii': self._ii, | |||
|
197 | '_iii': self._iii, | |||
|
198 | new_i : self._i00 } | |||
|
199 | self.shell.user_ns.update(to_main) | |||
|
200 | ||||
178 | def sync_inputs(self): |
|
201 | def sync_inputs(self): | |
179 | """Ensure raw and translated histories have same length.""" |
|
202 | """Ensure raw and translated histories have same length.""" | |
180 | if len(self.input_hist) != len (self.input_hist_raw): |
|
203 | if len(self.input_hist) != len (self.input_hist_raw): | |
@@ -403,7 +426,7 b' def rep_f(self, arg):' | |||||
403 | try: |
|
426 | try: | |
404 | lines = self.extract_input_slices(args, True) |
|
427 | lines = self.extract_input_slices(args, True) | |
405 | print("lines", lines) |
|
428 | print("lines", lines) | |
406 |
self.run |
|
429 | self.run_cell(lines) | |
407 | except ValueError: |
|
430 | except ValueError: | |
408 | print("Not found in recent history:", args) |
|
431 | print("Not found in recent history:", args) | |
409 |
|
432 |
@@ -430,11 +430,12 b' class InteractiveShell(Configurable, Magic):' | |||||
430 | self.dir_stack = [] |
|
430 | self.dir_stack = [] | |
431 |
|
431 | |||
432 | def init_logger(self): |
|
432 | def init_logger(self): | |
433 |
self.logger = Logger(self, logfname='ipython_log.py', |
|
433 | self.logger = Logger(self.home_dir, logfname='ipython_log.py', | |
434 | # local shortcut, this is used a LOT |
|
434 | logmode='rotate') | |
435 | self.log = self.logger.log |
|
|||
436 |
|
435 | |||
437 | def init_logstart(self): |
|
436 | def init_logstart(self): | |
|
437 | """Initialize logging in case it was requested at the command line. | |||
|
438 | """ | |||
438 | if self.logappend: |
|
439 | if self.logappend: | |
439 | self.magic_logstart(self.logappend + ' append') |
|
440 | self.magic_logstart(self.logappend + ' append') | |
440 | elif self.logfile: |
|
441 | elif self.logfile: | |
@@ -1839,7 +1840,6 b' class InteractiveShell(Configurable, Magic):' | |||||
1839 | # code out there that may rely on this). |
|
1840 | # code out there that may rely on this). | |
1840 | self.prefilter = self.prefilter_manager.prefilter_lines |
|
1841 | self.prefilter = self.prefilter_manager.prefilter_lines | |
1841 |
|
1842 | |||
1842 |
|
||||
1843 | def auto_rewrite_input(self, cmd): |
|
1843 | def auto_rewrite_input(self, cmd): | |
1844 | """Print to the screen the rewritten form of the user's command. |
|
1844 | """Print to the screen the rewritten form of the user's command. | |
1845 |
|
1845 | |||
@@ -2026,12 +2026,11 b' class InteractiveShell(Configurable, Magic):' | |||||
2026 | with prepended_to_syspath(dname): |
|
2026 | with prepended_to_syspath(dname): | |
2027 | try: |
|
2027 | try: | |
2028 | with open(fname) as thefile: |
|
2028 | with open(fname) as thefile: | |
2029 | script = thefile.read() |
|
2029 | # self.run_cell currently captures all exceptions | |
2030 | # self.runlines currently captures all exceptions |
|
2030 | # raised in user code. It would be nice if there were | |
2031 | # raise in user code. It would be nice if there were |
|
|||
2032 | # versions of runlines, execfile that did raise, so |
|
2031 | # versions of runlines, execfile that did raise, so | |
2033 | # we could catch the errors. |
|
2032 | # we could catch the errors. | |
2034 |
self.run |
|
2033 | self.run_cell(thefile.read()) | |
2035 | except: |
|
2034 | except: | |
2036 | self.showtraceback() |
|
2035 | self.showtraceback() | |
2037 | warn('Unknown failure executing file: <%s>' % fname) |
|
2036 | warn('Unknown failure executing file: <%s>' % fname) | |
@@ -2099,6 +2098,7 b' class InteractiveShell(Configurable, Magic):' | |||||
2099 | # Store raw and processed history |
|
2098 | # Store raw and processed history | |
2100 | self.history_manager.store_inputs(ipy_cell, cell) |
|
2099 | self.history_manager.store_inputs(ipy_cell, cell) | |
2101 |
|
2100 | |||
|
2101 | self.logger.log(ipy_cell, cell) | |||
2102 | # dbg code!!! |
|
2102 | # dbg code!!! | |
2103 | if 0: |
|
2103 | if 0: | |
2104 | def myapp(self, val): # dbg |
|
2104 | def myapp(self, val): # dbg |
@@ -20,9 +20,7 b' class Macro(IPyAutocall):' | |||||
20 | """ |
|
20 | """ | |
21 |
|
21 | |||
22 | def __init__(self,data): |
|
22 | def __init__(self,data): | |
23 |
|
23 | # store the macro value, as a single string which can be executed | ||
24 | # store the macro value, as a single string which can be evaluated by |
|
|||
25 | # runlines() |
|
|||
26 | self.value = ''.join(data).rstrip()+'\n' |
|
24 | self.value = ''.join(data).rstrip()+'\n' | |
27 |
|
25 | |||
28 | def __str__(self): |
|
26 | def __str__(self): | |
@@ -34,7 +32,7 b' class Macro(IPyAutocall):' | |||||
34 | def __call__(self,*args): |
|
32 | def __call__(self,*args): | |
35 | IPython.utils.io.Term.cout.flush() |
|
33 | IPython.utils.io.Term.cout.flush() | |
36 | self._ip.user_ns['_margv'] = args |
|
34 | self._ip.user_ns['_margv'] = args | |
37 |
self._ip.run |
|
35 | self._ip.run_cell(self.value) | |
38 |
|
36 | |||
39 | def __getstate__(self): |
|
37 | def __getstate__(self): | |
40 | """ needed for safe pickling via %store """ |
|
38 | """ needed for safe pickling via %store """ |
@@ -41,11 +41,6 b' except ImportError:' | |||||
41 | except ImportError: |
|
41 | except ImportError: | |
42 | profile = pstats = None |
|
42 | profile = pstats = None | |
43 |
|
43 | |||
44 | # print_function was added to __future__ in Python2.6, remove this when we drop |
|
|||
45 | # 2.5 compatibility |
|
|||
46 | if not hasattr(__future__,'CO_FUTURE_PRINT_FUNCTION'): |
|
|||
47 | __future__.CO_FUTURE_PRINT_FUNCTION = 65536 |
|
|||
48 |
|
||||
49 | import IPython |
|
44 | import IPython | |
50 | from IPython.core import debugger, oinspect |
|
45 | from IPython.core import debugger, oinspect | |
51 | from IPython.core.error import TryNext |
|
46 | from IPython.core.error import TryNext | |
@@ -2331,7 +2326,7 b' Currently the magic system has the following functions:\\n"""' | |||||
2331 | else: |
|
2326 | else: | |
2332 | print 'done. Executing edited code...' |
|
2327 | print 'done. Executing edited code...' | |
2333 | if opts_r: |
|
2328 | if opts_r: | |
2334 |
self.shell.run |
|
2329 | self.shell.run_cell(file_read(filename)) | |
2335 | else: |
|
2330 | else: | |
2336 | self.shell.safe_execfile(filename,self.shell.user_ns, |
|
2331 | self.shell.safe_execfile(filename,self.shell.user_ns, | |
2337 | self.shell.user_ns) |
|
2332 | self.shell.user_ns) | |
@@ -2992,7 +2987,7 b' Defaulting color scheme to \'NoColor\'"""' | |||||
2992 | (input.startswith(start) or input.startswith(start_magic)): |
|
2987 | (input.startswith(start) or input.startswith(start_magic)): | |
2993 | #print 'match',`input` # dbg |
|
2988 | #print 'match',`input` # dbg | |
2994 | print 'Executing:',input, |
|
2989 | print 'Executing:',input, | |
2995 |
self.shell.run |
|
2990 | self.shell.run_cell(input) | |
2996 | return |
|
2991 | return | |
2997 | print 'No previous input matching `%s` found.' % start |
|
2992 | print 'No previous input matching `%s` found.' % start | |
2998 |
|
2993 |
@@ -373,10 +373,6 b' class PrefilterManager(Configurable):' | |||||
373 | # print "prefilter_line: ", line, continue_prompt |
|
373 | # print "prefilter_line: ", line, continue_prompt | |
374 | # All handlers *must* return a value, even if it's blank (''). |
|
374 | # All handlers *must* return a value, even if it's blank (''). | |
375 |
|
375 | |||
376 | # Lines are NOT logged here. Handlers should process the line as |
|
|||
377 | # needed, update the cache AND log it (so that the input cache array |
|
|||
378 | # stays synced). |
|
|||
379 |
|
||||
380 | # save the line away in case we crash, so the post-mortem handler can |
|
376 | # save the line away in case we crash, so the post-mortem handler can | |
381 | # record it |
|
377 | # record it | |
382 | self.shell._last_input_line = line |
|
378 | self.shell._last_input_line = line | |
@@ -792,7 +788,6 b' class PrefilterHandler(Configurable):' | |||||
792 | ): |
|
788 | ): | |
793 | line = '' |
|
789 | line = '' | |
794 |
|
790 | |||
795 | self.shell.log(line, line, continue_prompt) |
|
|||
796 | return line |
|
791 | return line | |
797 |
|
792 | |||
798 | def __str__(self): |
|
793 | def __str__(self): | |
@@ -811,7 +806,6 b' class AliasHandler(PrefilterHandler):' | |||||
811 | line_out = '%sget_ipython().system(%s)' % (line_info.pre_whitespace, |
|
806 | line_out = '%sget_ipython().system(%s)' % (line_info.pre_whitespace, | |
812 | make_quoted_expr(transformed)) |
|
807 | make_quoted_expr(transformed)) | |
813 |
|
808 | |||
814 | self.shell.log(line_info.line, line_out, line_info.continue_prompt) |
|
|||
815 | return line_out |
|
809 | return line_out | |
816 |
|
810 | |||
817 |
|
811 | |||
@@ -840,8 +834,6 b' class ShellEscapeHandler(PrefilterHandler):' | |||||
840 | cmd = line.lstrip().lstrip(ESC_SHELL) |
|
834 | cmd = line.lstrip().lstrip(ESC_SHELL) | |
841 | line_out = '%sget_ipython().system(%s)' % (line_info.pre_whitespace, |
|
835 | line_out = '%sget_ipython().system(%s)' % (line_info.pre_whitespace, | |
842 | make_quoted_expr(cmd)) |
|
836 | make_quoted_expr(cmd)) | |
843 | # update cache/log and return |
|
|||
844 | self.shell.log(line, line_out, line_info.continue_prompt) |
|
|||
845 | return line_out |
|
837 | return line_out | |
846 |
|
838 | |||
847 |
|
839 | |||
@@ -856,7 +848,6 b' class MagicHandler(PrefilterHandler):' | |||||
856 | the_rest = line_info.the_rest |
|
848 | the_rest = line_info.the_rest | |
857 | cmd = '%sget_ipython().magic(%s)' % (line_info.pre_whitespace, |
|
849 | cmd = '%sget_ipython().magic(%s)' % (line_info.pre_whitespace, | |
858 | make_quoted_expr(ifun + " " + the_rest)) |
|
850 | make_quoted_expr(ifun + " " + the_rest)) | |
859 | self.shell.log(line_info.line, cmd, line_info.continue_prompt) |
|
|||
860 | return cmd |
|
851 | return cmd | |
861 |
|
852 | |||
862 |
|
853 | |||
@@ -877,7 +868,6 b' class AutoHandler(PrefilterHandler):' | |||||
877 |
|
868 | |||
878 | # This should only be active for single-line input! |
|
869 | # This should only be active for single-line input! | |
879 | if continue_prompt: |
|
870 | if continue_prompt: | |
880 | self.shell.log(line,line,continue_prompt) |
|
|||
881 | return line |
|
871 | return line | |
882 |
|
872 | |||
883 | force_auto = isinstance(obj, IPyAutocall) |
|
873 | force_auto = isinstance(obj, IPyAutocall) | |
@@ -918,9 +908,6 b' class AutoHandler(PrefilterHandler):' | |||||
918 | if auto_rewrite: |
|
908 | if auto_rewrite: | |
919 | self.shell.auto_rewrite_input(newcmd) |
|
909 | self.shell.auto_rewrite_input(newcmd) | |
920 |
|
910 | |||
921 | # log what is now valid Python, not the actual user input (without the |
|
|||
922 | # final newline) |
|
|||
923 | self.shell.log(line,newcmd,continue_prompt) |
|
|||
924 | return newcmd |
|
911 | return newcmd | |
925 |
|
912 | |||
926 |
|
913 | |||
@@ -947,7 +934,6 b' class HelpHandler(PrefilterHandler):' | |||||
947 | line = line[1:] |
|
934 | line = line[1:] | |
948 | elif line[-1]==ESC_HELP: |
|
935 | elif line[-1]==ESC_HELP: | |
949 | line = line[:-1] |
|
936 | line = line[:-1] | |
950 | self.shell.log(line, '#?'+line, line_info.continue_prompt) |
|
|||
951 | if line: |
|
937 | if line: | |
952 | #print 'line:<%r>' % line # dbg |
|
938 | #print 'line:<%r>' % line # dbg | |
953 | self.shell.magic_pinfo(line) |
|
939 | self.shell.magic_pinfo(line) |
@@ -571,7 +571,7 b' class IPythonApp(Application):' | |||||
571 | try: |
|
571 | try: | |
572 | self.log.info("Running code in user namespace: %s" % |
|
572 | self.log.info("Running code in user namespace: %s" % | |
573 | line) |
|
573 | line) | |
574 |
self.shell.run |
|
574 | self.shell.run_cell(line) | |
575 | except: |
|
575 | except: | |
576 | self.log.warn("Error in executing line in user " |
|
576 | self.log.warn("Error in executing line in user " | |
577 | "namespace: %s" % line) |
|
577 | "namespace: %s" % line) | |
@@ -616,7 +616,7 b' class IPythonApp(Application):' | |||||
616 | try: |
|
616 | try: | |
617 | self.log.info("Running code given at command line (-c): %s" % |
|
617 | self.log.info("Running code given at command line (-c): %s" % | |
618 | line) |
|
618 | line) | |
619 |
self.shell.run |
|
619 | self.shell.run_cell(line) | |
620 | except: |
|
620 | except: | |
621 | self.log.warn("Error in executing line in user namespace: %s" % |
|
621 | self.log.warn("Error in executing line in user namespace: %s" % | |
622 | line) |
|
622 | line) |
@@ -248,7 +248,7 b' class Demo(object):' | |||||
248 | self.ip_ns = ip.user_ns |
|
248 | self.ip_ns = ip.user_ns | |
249 | self.ip_colorize = ip.pycolorize |
|
249 | self.ip_colorize = ip.pycolorize | |
250 | self.ip_showtb = ip.showtraceback |
|
250 | self.ip_showtb = ip.showtraceback | |
251 |
self.ip_run |
|
251 | self.ip_run_cell = ip.run_cell | |
252 | self.shell = ip |
|
252 | self.shell = ip | |
253 |
|
253 | |||
254 | # load user data and initialize data structures |
|
254 | # load user data and initialize data structures | |
@@ -411,7 +411,7 b' class Demo(object):' | |||||
411 | print >>IPython.utils.io.Term.cout, block, |
|
411 | print >>IPython.utils.io.Term.cout, block, | |
412 | sys.stdout.flush() |
|
412 | sys.stdout.flush() | |
413 |
|
413 | |||
414 |
def run |
|
414 | def run_cell(self,source): | |
415 | """Execute a string with one or more lines of code""" |
|
415 | """Execute a string with one or more lines of code""" | |
416 |
|
416 | |||
417 | exec source in self.user_ns |
|
417 | exec source in self.user_ns | |
@@ -449,7 +449,7 b' class Demo(object):' | |||||
449 | try: |
|
449 | try: | |
450 | save_argv = sys.argv |
|
450 | save_argv = sys.argv | |
451 | sys.argv = self.sys_argv |
|
451 | sys.argv = self.sys_argv | |
452 |
self.run |
|
452 | self.run_cell(next_block) | |
453 | self.post_cmd() |
|
453 | self.post_cmd() | |
454 | finally: |
|
454 | finally: | |
455 | sys.argv = save_argv |
|
455 | sys.argv = save_argv | |
@@ -496,10 +496,10 b' class IPythonDemo(Demo):' | |||||
496 | class requires the input to be valid, pure Python code. |
|
496 | class requires the input to be valid, pure Python code. | |
497 | """ |
|
497 | """ | |
498 |
|
498 | |||
499 |
def run |
|
499 | def run_cell(self,source): | |
500 | """Execute a string with one or more lines of code""" |
|
500 | """Execute a string with one or more lines of code""" | |
501 |
|
501 | |||
502 |
self.shell.run |
|
502 | self.shell.run_cell(source) | |
503 |
|
503 | |||
504 | class LineDemo(Demo): |
|
504 | class LineDemo(Demo): | |
505 | """Demo where each line is executed as a separate block. |
|
505 | """Demo where each line is executed as a separate block. |
@@ -214,14 +214,8 b' class Kernel(Configurable):' | |||||
214 | # statements in that code will obviously still execute. |
|
214 | # statements in that code will obviously still execute. | |
215 | shell.runcode(code) |
|
215 | shell.runcode(code) | |
216 | else: |
|
216 | else: | |
217 |
# FIXME: |
|
217 | # FIXME: the shell calls the exception handler itself. | |
218 | shell._reply_content = None |
|
218 | shell._reply_content = None | |
219 |
|
||||
220 | # For now leave this here until we're sure we can stop using it |
|
|||
221 | #shell.runlines(code) |
|
|||
222 |
|
||||
223 | # Experimental: cell mode! Test more before turning into |
|
|||
224 | # default and removing the hacks around runlines. |
|
|||
225 | shell.run_cell(code) |
|
219 | shell.run_cell(code) | |
226 | except: |
|
220 | except: | |
227 | status = u'error' |
|
221 | status = u'error' |
General Comments 0
You need to be logged in to leave comments.
Login now