##// END OF EJS Templates
rollback UsageError for cell magic mid-cell...
MinRK -
Show More
@@ -3,7 +3,6 b' import functools'
3 import re
3 import re
4 from StringIO import StringIO
4 from StringIO import StringIO
5
5
6 from IPython.core.error import UsageError
7 from IPython.core.splitinput import LineInfo
6 from IPython.core.splitinput import LineInfo
8 from IPython.utils import tokenize2
7 from IPython.utils import tokenize2
9 from IPython.utils.openpy import cookie_comment_re
8 from IPython.utils.openpy import cookie_comment_re
@@ -233,15 +232,6 b' def _tr_magic(line_info):'
233 cmd = ' '.join([line_info.ifun, line_info.the_rest]).strip()
232 cmd = ' '.join([line_info.ifun, line_info.the_rest]).strip()
234 return tpl % (line_info.pre, cmd)
233 return tpl % (line_info.pre, cmd)
235
234
236 def _tr_cellmagic(line_info):
237 """Translate lines escaped with %%
238
239 Only happens when cell magics are mid-cell, which is an error.
240 """
241 raise UsageError("Cannot call cell magics (%s%s) mid-cell" %
242 (ESC_MAGIC2, line_info.ifun)
243 )
244
245 def _tr_quote(line_info):
235 def _tr_quote(line_info):
246 "Translate lines escaped with: ,"
236 "Translate lines escaped with: ,"
247 return '%s%s("%s")' % (line_info.pre, line_info.ifun,
237 return '%s%s("%s")' % (line_info.pre, line_info.ifun,
@@ -262,7 +252,6 b' tr = { ESC_SHELL : _tr_system,'
262 ESC_HELP : _tr_help,
252 ESC_HELP : _tr_help,
263 ESC_HELP2 : _tr_help,
253 ESC_HELP2 : _tr_help,
264 ESC_MAGIC : _tr_magic,
254 ESC_MAGIC : _tr_magic,
265 ESC_MAGIC2 : _tr_cellmagic,
266 ESC_QUOTE : _tr_quote,
255 ESC_QUOTE : _tr_quote,
267 ESC_QUOTE2 : _tr_quote2,
256 ESC_QUOTE2 : _tr_quote2,
268 ESC_PAREN : _tr_paren }
257 ESC_PAREN : _tr_paren }
@@ -2599,14 +2599,10 b' class InteractiveShell(SingletonConfigurable):'
2599
2599
2600 if silent:
2600 if silent:
2601 store_history = False
2601 store_history = False
2602
2602
2603 try:
2603 self.input_transformer_manager.push(raw_cell)
2604 self.input_transformer_manager.push(raw_cell)
2604 cell = self.input_transformer_manager.source_reset()
2605 cell = self.input_transformer_manager.source_reset()
2605
2606 except UsageError as e:
2607 self.show_usage_error(e)
2608 return
2609
2610 # Our own compiler remembers the __future__ environment. If we want to
2606 # Our own compiler remembers the __future__ environment. If we want to
2611 # run code with a separate __future__ environment, use the default
2607 # run code with a separate __future__ environment, use the default
2612 # compiler
2608 # compiler
@@ -43,7 +43,7 b' from IPython.utils.encoding import get_stream_enc'
43
43
44 line_split = re.compile("""
44 line_split = re.compile("""
45 ^(\s*) # any leading space
45 ^(\s*) # any leading space
46 ([,;/]|%%?|!!?|\?\??)? # escape character or characters
46 ([,;/%]|!!?|\?\??)? # escape character or characters
47 \s*(%{0,2}[\w\.\*]*) # function/method, possibly with leading %
47 \s*(%{0,2}[\w\.\*]*) # function/method, possibly with leading %
48 # to correctly treat things like '?%magic'
48 # to correctly treat things like '?%magic'
49 (.*?$|$) # rest of line
49 (.*?$|$) # rest of line
General Comments 0
You need to be logged in to leave comments. Login now