##// END OF EJS Templates
Rename a few methods as per review, also complete some docstrings.
Fernando Perez -
Show More
@@ -775,7 +775,7 b' class IPythonInputSplitter(InputSplitter):'
775 # get it all working, as right now changing the return API of our
775 # get it all working, as right now changing the return API of our
776 # methods would require major refactoring.
776 # methods would require major refactoring.
777 self.cell_magic_parts = [body]
777 self.cell_magic_parts = [body]
778 tpl = 'get_ipython()._cell_magic(%r, %r)'
778 tpl = 'get_ipython()._run_cached_cell_magic(%r, %r)'
779 tlines = tpl % (magic_name, line)
779 tlines = tpl % (magic_name, line)
780 self._store(tlines)
780 self._store(tlines)
781 self._store(lines, self._buffer_raw, 'source_raw')
781 self._store(lines, self._buffer_raw, 'source_raw')
@@ -2021,7 +2021,7 b' class InteractiveShell(SingletonConfigurable):'
2021 # even need a centralize colors management object.
2021 # even need a centralize colors management object.
2022 self.magic('colors %s' % self.colors)
2022 self.magic('colors %s' % self.colors)
2023
2023
2024 def line_magic(self, magic_name, line):
2024 def run_line_magic(self, magic_name, line):
2025 """Execute the given line magic.
2025 """Execute the given line magic.
2026
2026
2027 Parameters
2027 Parameters
@@ -2054,8 +2054,19 b' class InteractiveShell(SingletonConfigurable):'
2054 result = fn(*args)
2054 result = fn(*args)
2055 return result
2055 return result
2056
2056
2057 def cell_magic(self, magic_name, line, cell):
2057 def run_cell_magic(self, magic_name, line, cell):
2058 """Execute the given cell magic.
2058 """Execute the given cell magic.
2059
2060 Parameters
2061 ----------
2062 magic_name : str
2063 Name of the desired magic function, without '%' prefix.
2064
2065 line : str
2066 The rest of the first input line as a single string.
2067
2068 cell : str
2069 The body of the cell as a (possibly multiline) string.
2059 """
2070 """
2060 fn = self.find_cell_magic(magic_name)
2071 fn = self.find_cell_magic(magic_name)
2061 if fn is None:
2072 if fn is None:
@@ -2093,7 +2104,7 b' class InteractiveShell(SingletonConfigurable):'
2093 return self.magics_manager.magics[magic_kind].get(magic_name)
2104 return self.magics_manager.magics[magic_kind].get(magic_name)
2094
2105
2095 def magic(self, arg_s):
2106 def magic(self, arg_s):
2096 """DEPRECATED. Use line_magic() instead.
2107 """DEPRECATED. Use run_line_magic() instead.
2097
2108
2098 Call a magic function by name.
2109 Call a magic function by name.
2099
2110
@@ -2114,7 +2125,7 b' class InteractiveShell(SingletonConfigurable):'
2114 # TODO: should we issue a loud deprecation warning here?
2125 # TODO: should we issue a loud deprecation warning here?
2115 magic_name, _, magic_arg_s = arg_s.partition(' ')
2126 magic_name, _, magic_arg_s = arg_s.partition(' ')
2116 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
2127 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
2117 return self.line_magic(magic_name, magic_arg_s)
2128 return self.run_line_magic(magic_name, magic_arg_s)
2118
2129
2119 #-------------------------------------------------------------------------
2130 #-------------------------------------------------------------------------
2120 # Things related to macros
2131 # Things related to macros
@@ -2484,12 +2495,12 b' class InteractiveShell(SingletonConfigurable):'
2484 self.showtraceback()
2495 self.showtraceback()
2485 warn('Unknown failure executing module: <%s>' % mod_name)
2496 warn('Unknown failure executing module: <%s>' % mod_name)
2486
2497
2487 def _cell_magic(self, magic_name, line):
2498 def _run_cached_cell_magic(self, magic_name, line):
2488 """Special method to call a cell magic with the data stored in self.
2499 """Special method to call a cell magic with the data stored in self.
2489 """
2500 """
2490 cell = self._current_cell_magic_body
2501 cell = self._current_cell_magic_body
2491 self._current_cell_magic_body = None
2502 self._current_cell_magic_body = None
2492 return self.cell_magic(magic_name, line, cell)
2503 return self.run_cell_magic(magic_name, line, cell)
2493
2504
2494 def run_cell(self, raw_cell, store_history=False, silent=False):
2505 def run_cell(self, raw_cell, store_history=False, silent=False):
2495 """Run a complete IPython cell.
2506 """Run a complete IPython cell.
@@ -759,7 +759,7 b' class CellModeCellMagics(unittest.TestCase):'
759 sp.push(src)
759 sp.push(src)
760 nt.assert_equal(sp.cell_magic_parts, ['body\n'])
760 nt.assert_equal(sp.cell_magic_parts, ['body\n'])
761 out = sp.source
761 out = sp.source
762 ref = u"get_ipython()._cell_magic(u'cellm', u'line')\n"
762 ref = u"get_ipython()._run_cached_cell_magic(u'cellm', u'line')\n"
763 nt.assert_equal(out, ref)
763 nt.assert_equal(out, ref)
764
764
765 def test_incremental(self):
765 def test_incremental(self):
@@ -793,7 +793,7 b' class LineModeCellMagics(unittest.TestCase):'
793 sp.push(src)
793 sp.push(src)
794 nt.assert_equal(sp.cell_magic_parts, ['body\n'])
794 nt.assert_equal(sp.cell_magic_parts, ['body\n'])
795 out = sp.source
795 out = sp.source
796 ref = u"get_ipython()._cell_magic(u'cellm', u'line')\n"
796 ref = u"get_ipython()._run_cached_cell_magic(u'cellm', u'line')\n"
797 nt.assert_equal(out, ref)
797 nt.assert_equal(out, ref)
798
798
799 def test_incremental(self):
799 def test_incremental(self):
@@ -496,7 +496,7 b' class CellMagicTestCase(TestCase):'
496
496
497 def check_ident(self, magic):
497 def check_ident(self, magic):
498 # Manually called, we get the result
498 # Manually called, we get the result
499 out = _ip.cell_magic(magic, 'a', 'b')
499 out = _ip.run_cell_magic(magic, 'a', 'b')
500 nt.assert_equals(out, ('a','b'))
500 nt.assert_equals(out, ('a','b'))
501 # Via run_cell, it goes into the user's namespace via displayhook
501 # Via run_cell, it goes into the user's namespace via displayhook
502 _ip.run_cell('%%' + magic +' c\nd')
502 _ip.run_cell('%%' + magic +' c\nd')
General Comments 0
You need to be logged in to leave comments. Login now