##// END OF EJS Templates
result_display can return value. ipapi.is_ipython_session(). %paste -> %cpaste.
vivainio -
Show More
@@ -1,7 +1,7 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2 """Magic functions for InteractiveShell.
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 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
7 # Copyright (C) 2001 Janko Hauser <jhauser@zscout.de> and
@@ -2760,7 +2760,7 b' Defaulting color scheme to \'NoColor\'"""'
2760 page(self.shell.pycolorize(file_read(filename)),
2760 page(self.shell.pycolorize(file_read(filename)),
2761 screen_lines=self.shell.rc.screen_length)
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 """Allows you to paste & execute a pre-formatted code block from
2764 """Allows you to paste & execute a pre-formatted code block from
2765 clipboard.
2765 clipboard.
2766
2766
@@ -2772,7 +2772,7 b' Defaulting color scheme to \'NoColor\'"""'
2772 method definitions. The executed block is also assigned to variable
2772 method definitions. The executed block is also assigned to variable
2773 named 'pasted_block' for later editing with '%edit pasted_block'.
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 This assigns the pasted block to variable 'foo' as string, without
2776 This assigns the pasted block to variable 'foo' as string, without
2777 dedenting or executing it.
2777 dedenting or executing it.
2778
2778
@@ -2,7 +2,7 b''
2 """
2 """
3 Classes for handling input/output prompts.
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 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
8 # Copyright (C) 2001-2006 Fernando Perez <fperez@colorado.edu>
@@ -497,9 +497,7 b' class CachedOutput:'
497 if arg is not None:
497 if arg is not None:
498 cout_write = Term.cout.write # fast lookup
498 cout_write = Term.cout.write # fast lookup
499 # first handle the cache and counters
499 # first handle the cache and counters
500 # but avoid recursive reference when displaying _oh/Out
500
501 if arg is not self.user_ns['_oh']:
502 self.update(arg)
503 # do not print output if input ends in ';'
501 # do not print output if input ends in ';'
504 if self.input_hist[self.prompt_count].endswith(';\n'):
502 if self.input_hist[self.prompt_count].endswith(';\n'):
505 return
503 return
@@ -516,7 +514,18 b' class CachedOutput:'
516 return None
514 return None
517
515
518 # and now call a possibly user-defined print mechanism
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 if self.logger.log_output:
529 if self.logger.log_output:
521 self.logger.log_write(repr(arg),'output')
530 self.logger.log_write(repr(arg),'output')
522 cout_write(self.output_sep2)
531 cout_write(self.output_sep2)
@@ -529,7 +538,7 b' class CachedOutput:'
529 display, e.g. when your own objects need special formatting.
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 # Assign the default display method:
543 # Assign the default display method:
535 display = _display
544 display = _display
@@ -32,7 +32,7 b" ip_set_hook('editor',myiphooks.calljed)"
32 The ip_set_hook function is put by IPython into the builtin namespace, so it
32 The ip_set_hook function is put by IPython into the builtin namespace, so it
33 is always available from all running code.
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 # Copyright (C) 2005 Fernando Perez. <fperez@colorado.edu>
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 from IPython import Release
44 from IPython import Release
45 from IPython import ipapi
45 __author__ = '%s <%s>' % Release.authors['Fernando']
46 __author__ = '%s <%s>' % Release.authors['Fernando']
46 __license__ = Release.license
47 __license__ = Release.license
47 __version__ = Release.version
48 __version__ = Release.version
@@ -96,8 +97,6 b' def fix_error_editor(self,filename,linenum,column,msg):'
96 finally:
97 finally:
97 t.close()
98 t.close()
98
99
99 class TryNext(Exception):
100 pass
101
100
102 class CommandChainDispatcher:
101 class CommandChainDispatcher:
103 """ Dispatch calls to a chain of commands until some func can handle it
102 """ Dispatch calls to a chain of commands until some func can handle it
@@ -125,7 +124,7 b' class CommandChainDispatcher:'
125 try:
124 try:
126 ret = cmd(*args, **kw)
125 ret = cmd(*args, **kw)
127 return ret
126 return ret
128 except TryNext:
127 except ipapi.TryNext:
129 pass
128 pass
130
129
131 def __str__(self):
130 def __str__(self):
@@ -146,4 +145,6 b' def result_display(self,arg):'
146 print >>Term.cout, out
145 print >>Term.cout, out
147 else:
146 else:
148 print >>Term.cout, arg
147 print >>Term.cout, arg
148 # the default display hook doesn't manipulate the value to put in history
149 return None
149 No newline at end of file
150
@@ -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 def _init_with_shell(ip):
75 def _init_with_shell(ip):
64 global magic
76 global magic
65 magic = ip.ipmagic
77 magic = ip.ipmagic
@@ -151,7 +163,12 b' def launch_new_instance():'
151 import IPython
163 import IPython
152
164
153 IPython.Shell.start().mainloop()
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
172 # Yes, this is the shell object or None - however, it's an implementation
157 No newline at end of file
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 2006-01-23 Ville Vainio <vivainio@gmail.com>
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 2006-01-22 Ville Vainio <vivainio@gmail.com>
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