##// END OF EJS Templates
result_display can return value. ipapi.is_ipython_session(). %paste -> %cpaste.
vivainio -
Show More
@@ -1,7 +1,7 b''
1 1 # -*- coding: utf-8 -*-
2 2 """Magic functions for InteractiveShell.
3 3
4 $Id: Magic.py 1071 2006-01-23 21:30:41Z vivainio $"""
4 $Id: Magic.py 1076 2006-01-24 17:27:05Z vivainio $"""
5 5
6 6 #*****************************************************************************
7 7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -2760,7 +2760,7 b' Defaulting color scheme to \'NoColor\'"""'
2760 2760 page(self.shell.pycolorize(file_read(filename)),
2761 2761 screen_lines=self.shell.rc.screen_length)
2762 2762
2763 def magic_paste(self, parameter_s=''):
2763 def magic_cpaste(self, parameter_s=''):
2764 2764 """Allows you to paste & execute a pre-formatted code block from
2765 2765 clipboard.
2766 2766
@@ -2772,7 +2772,7 b' Defaulting color scheme to \'NoColor\'"""'
2772 2772 method definitions. The executed block is also assigned to variable
2773 2773 named 'pasted_block' for later editing with '%edit pasted_block'.
2774 2774
2775 You can also pass a variable name as an argument, e.g. '%paste foo'.
2775 You can also pass a variable name as an argument, e.g. '%cpaste foo'.
2776 2776 This assigns the pasted block to variable 'foo' as string, without
2777 2777 dedenting or executing it.
2778 2778
@@ -2,7 +2,7 b''
2 2 """
3 3 Classes for handling input/output prompts.
4 4
5 $Id: Prompts.py 1020 2006-01-14 13:22:58Z vivainio $"""
5 $Id: Prompts.py 1076 2006-01-24 17:27:05Z vivainio $"""
6 6
7 7 #*****************************************************************************
8 8 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
@@ -497,9 +497,7 b' class CachedOutput:'
497 497 if arg is not None:
498 498 cout_write = Term.cout.write # fast lookup
499 499 # first handle the cache and counters
500 # but avoid recursive reference when displaying _oh/Out
501 if arg is not self.user_ns['_oh']:
502 self.update(arg)
500
503 501 # do not print output if input ends in ';'
504 502 if self.input_hist[self.prompt_count].endswith(';\n'):
505 503 return
@@ -516,7 +514,18 b' class CachedOutput:'
516 514 return None
517 515
518 516 # and now call a possibly user-defined print mechanism
519 self.display(arg)
517 manipulated_val = self.display(arg)
518
519 # user display hooks can change the variable to be stored in
520 # output history
521
522 if manipulated_val is not None:
523 arg = manipulated_val
524
525 # avoid recursive reference when displaying _oh/Out
526 if arg is not self.user_ns['_oh']:
527 self.update(arg)
528
520 529 if self.logger.log_output:
521 530 self.logger.log_write(repr(arg),'output')
522 531 cout_write(self.output_sep2)
@@ -529,7 +538,7 b' class CachedOutput:'
529 538 display, e.g. when your own objects need special formatting.
530 539 """
531 540
532 self.shell.hooks.result_display(arg)
541 return self.shell.hooks.result_display(arg)
533 542
534 543 # Assign the default display method:
535 544 display = _display
@@ -32,7 +32,7 b" ip_set_hook('editor',myiphooks.calljed)"
32 32 The ip_set_hook function is put by IPython into the builtin namespace, so it
33 33 is always available from all running code.
34 34
35 $Id: hooks.py 1020 2006-01-14 13:22:58Z vivainio $"""
35 $Id: hooks.py 1076 2006-01-24 17:27:05Z vivainio $"""
36 36
37 37 #*****************************************************************************
38 38 # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu>
@@ -42,6 +42,7 b' $Id: hooks.py 1020 2006-01-14 13:22:58Z vivainio $"""'
42 42 #*****************************************************************************
43 43
44 44 from IPython import Release
45 from IPython import ipapi
45 46 __author__ = '%s <%s>' % Release.authors['Fernando']
46 47 __license__ = Release.license
47 48 __version__ = Release.version
@@ -96,8 +97,6 b' def fix_error_editor(self,filename,linenum,column,msg):'
96 97 finally:
97 98 t.close()
98 99
99 class TryNext(Exception):
100 pass
101 100
102 101 class CommandChainDispatcher:
103 102 """ Dispatch calls to a chain of commands until some func can handle it
@@ -125,7 +124,7 b' class CommandChainDispatcher:'
125 124 try:
126 125 ret = cmd(*args, **kw)
127 126 return ret
128 except TryNext:
127 except ipapi.TryNext:
129 128 pass
130 129
131 130 def __str__(self):
@@ -146,4 +145,6 b' def result_display(self,arg):'
146 145 print >>Term.cout, out
147 146 else:
148 147 print >>Term.cout, arg
148 # the default display hook doesn't manipulate the value to put in history
149 return None
149 150 No newline at end of file
@@ -60,6 +60,18 b' print "done!"'
60 60
61 61 '''
62 62
63
64 class TryNext(Exception):
65 """ Try next hook exception.
66
67 Raise this in your hook function to indicate that the next
68 hook handler should be used to handle the operation.
69 """
70
71
72
73 __IP = None
74
63 75 def _init_with_shell(ip):
64 76 global magic
65 77 magic = ip.ipmagic
@@ -151,7 +163,12 b' def launch_new_instance():'
151 163 import IPython
152 164
153 165 IPython.Shell.start().mainloop()
166
167 def is_ipython_session():
168 """ Return a true value if running inside IPython.
154 169
170 """
155 171
156
157 No newline at end of file
172 # Yes, this is the shell object or None - however, it's an implementation
173 # detail and should not be relied on, only truth value matters.
174 return __IP
@@ -1,6 +1,15 b''
1 2006-01-24 Ville Vainio <vivainio@gmail.com>
2
3 * iplib.py, hooks.py: 'result_display' hook can return a non-None
4 value to manipulate resulting history entry.
5
6 * ipapi.py: Moved TryNext here from hooks.py, added
7 is_ipython_session() to determine whether we are running
8 inside an ipython session.
9
1 10 2006-01-23 Ville Vainio <vivainio@gmail.com>
2 11
3 * Added %paste magic for pasting python code
12 * Added %cpaste magic for pasting python code
4 13
5 14 2006-01-22 Ville Vainio <vivainio@gmail.com>
6 15
General Comments 0
You need to be logged in to leave comments. Login now