##// END OF EJS Templates
fix for #10327 : get_ipython.magic() replaced with get_ipython.run_line_magic()
adityausathe -
Show More
@@ -225,11 +225,14 b' def _tr_help(line_info):'
225
225
226 def _tr_magic(line_info):
226 def _tr_magic(line_info):
227 "Translate lines escaped with: %"
227 "Translate lines escaped with: %"
228 tpl = '%sget_ipython().magic(%r)'
228 tpl = '%sget_ipython().run_line_magic(%r, %r)'
229 if line_info.line.startswith(ESC_MAGIC2):
229 if line_info.line.startswith(ESC_MAGIC2):
230 return line_info.line
230 return line_info.line
231 cmd = ' '.join([line_info.ifun, line_info.the_rest]).strip()
231 cmd = ' '.join([line_info.ifun, line_info.the_rest]).strip()
232 return tpl % (line_info.pre, cmd)
232 #Prepare arguments for get_ipython().run_line_magic(magic_name, magic_args)
233 t_magic_name, _, t_magic_arg_s = cmd.partition(' ')
234 t_magic_name = t_magic_name.lstrip(ESC_MAGIC)
235 return tpl % (line_info.pre, t_magic_name, t_magic_arg_s)
233
236
234 def _tr_quote(line_info):
237 def _tr_quote(line_info):
235 "Translate lines escaped with: ,"
238 "Translate lines escaped with: ,"
@@ -514,12 +517,15 b' def assign_from_system(line):'
514 return assign_system_template % m.group('lhs', 'cmd')
517 return assign_system_template % m.group('lhs', 'cmd')
515
518
516 assign_magic_re = re.compile(r'{}%\s*(?P<cmd>.*)'.format(_assign_pat), re.VERBOSE)
519 assign_magic_re = re.compile(r'{}%\s*(?P<cmd>.*)'.format(_assign_pat), re.VERBOSE)
517 assign_magic_template = '%s = get_ipython().magic(%r)'
520 assign_magic_template = '%s = get_ipython().run_line_magic(%r, %r)'
518 @StatelessInputTransformer.wrap
521 @StatelessInputTransformer.wrap
519 def assign_from_magic(line):
522 def assign_from_magic(line):
520 """Transform assignment from magic commands (e.g. a = %who_ls)"""
523 """Transform assignment from magic commands (e.g. a = %who_ls)"""
521 m = assign_magic_re.match(line)
524 m = assign_magic_re.match(line)
522 if m is None:
525 if m is None:
523 return line
526 return line
524
527 #Prepare arguments for get_ipython().run_line_magic(magic_name, magic_args)
525 return assign_magic_template % m.group('lhs', 'cmd')
528 m_lhs, m_cmd = m.group('lhs', 'cmd')
529 t_magic_name, _, t_magic_arg_s = cmd.partition(' ')
530 t_magic_name = t_magic_name.lstrip(ESC_MAGIC)
531 return assign_magic_template % (m_lhs, t_magic_name, t_magic_arg_s)
@@ -61,7 +61,7 b' class HistoryMagics(Magics):'
61 source before executing it (things like magics or aliases are turned
61 source before executing it (things like magics or aliases are turned
62 into function calls, for example). With this option, you'll see the
62 into function calls, for example). With this option, you'll see the
63 native history instead of the user-entered version: '%%cd /' will be
63 native history instead of the user-entered version: '%%cd /' will be
64 seen as 'get_ipython().magic("%%cd /")' instead of '%%cd /'.
64 seen as 'get_ipython().run_line_magic("cd", "/")' instead of '%%cd /'.
65 """)
65 """)
66 @argument(
66 @argument(
67 '-f', dest='filename',
67 '-f', dest='filename',
@@ -589,8 +589,11 b' class MagicHandler(PrefilterHandler):'
589 """Execute magic functions."""
589 """Execute magic functions."""
590 ifun = line_info.ifun
590 ifun = line_info.ifun
591 the_rest = line_info.the_rest
591 the_rest = line_info.the_rest
592 cmd = '%sget_ipython().magic(%r)' % (line_info.pre_whitespace,
592 #Prepare arguments for get_ipython().run_line_magic(magic_name, magic_args)
593 (ifun + " " + the_rest))
593 t_arg_s = ifun + " " + the_rest
594 t_magic_name, _, t_magic_arg_s = t_arg_s.partition(' ')
595 t_magic_name = t_magic_name.lstrip(ESC_MAGIC)
596 cmd = '%sget_ipython().run_line_magic(%r, %r)' % (line_info.pre_whitespace, t_magic_name, t_magic_arg_s)
594 return cmd
597 return cmd
595
598
596
599
General Comments 0
You need to be logged in to leave comments. Login now