Show More
@@ -38,7 +38,7 from IPython.core import page | |||
|
38 | 38 | from IPython.core import prefilter |
|
39 | 39 | from IPython.core import shadowns |
|
40 | 40 | from IPython.core import ultratb |
|
41 | from IPython.core.alias import AliasManager | |
|
41 | from IPython.core.alias import AliasManager, AliasError | |
|
42 | 42 | from IPython.core.autocall import ExitAutocall |
|
43 | 43 | from IPython.core.builtin_trap import BuiltinTrap |
|
44 | 44 | from IPython.core.compilerop import CachingCompiler |
@@ -2129,22 +2129,18 class InteractiveShell(Configurable, Magic): | |||
|
2129 | 2129 | cell = self.input_splitter.source_reset() |
|
2130 | 2130 | |
|
2131 | 2131 | with self.builtin_trap: |
|
2132 | prefilter_failed = False | |
|
2132 | 2133 | if len(cell.splitlines()) == 1: |
|
2133 | 2134 | try: |
|
2134 | 2135 | cell = self.prefilter_manager.prefilter_lines(cell) |
|
2136 | except AliasError as e: | |
|
2137 | error(e) | |
|
2138 | prefilter_failed=True | |
|
2135 | 2139 | except Exception: |
|
2136 |
# don't allow prefilter errors to crash IPython |
|
|
2137 | # user code can be involved (e.g. aliases) | |
|
2140 | # don't allow prefilter errors to crash IPython | |
|
2138 | 2141 | self.showtraceback() |
|
2139 |
if |
|
|
2140 | self.history_manager.store_inputs(self.execution_count, | |
|
2141 | cell, raw_cell) | |
|
2142 | ||
|
2143 | self.logger.log(cell, raw_cell) | |
|
2144 | self.execution_count += 1 | |
|
2145 | ||
|
2146 | return | |
|
2147 | ||
|
2142 | prefilter_failed = True | |
|
2143 | ||
|
2148 | 2144 | # Store raw and processed history |
|
2149 | 2145 | if store_history: |
|
2150 | 2146 | self.history_manager.store_inputs(self.execution_count, |
@@ -2152,30 +2148,32 class InteractiveShell(Configurable, Magic): | |||
|
2152 | 2148 | |
|
2153 | 2149 | self.logger.log(cell, raw_cell) |
|
2154 | 2150 | |
|
2155 | cell_name = self.compile.cache(cell, self.execution_count) | |
|
2151 | if not prefilter_failed: | |
|
2152 | # don't run if prefilter failed | |
|
2153 | cell_name = self.compile.cache(cell, self.execution_count) | |
|
2156 | 2154 | |
|
2157 | with self.display_trap: | |
|
2158 | try: | |
|
2159 | code_ast = ast.parse(cell, filename=cell_name) | |
|
2160 | except (OverflowError, SyntaxError, ValueError, TypeError, | |
|
2161 | MemoryError): | |
|
2162 | self.showsyntaxerror() | |
|
2163 | self.execution_count += 1 | |
|
2164 | return None | |
|
2165 | ||
|
2166 | self.run_ast_nodes(code_ast.body, cell_name, | |
|
2167 | interactivity="last_expr") | |
|
2168 | ||
|
2169 | # Execute any registered post-execution functions. | |
|
2170 | for func, status in self._post_execute.iteritems(): | |
|
2171 | if not status: | |
|
2172 | continue | |
|
2155 | with self.display_trap: | |
|
2173 | 2156 | try: |
|
2174 | func() | |
|
2175 | except: | |
|
2176 |
|
|
|
2177 | # Deactivate failing function | |
|
2178 |
self. |
|
|
2157 | code_ast = ast.parse(cell, filename=cell_name) | |
|
2158 | except (OverflowError, SyntaxError, ValueError, TypeError, | |
|
2159 | MemoryError): | |
|
2160 | self.showsyntaxerror() | |
|
2161 | self.execution_count += 1 | |
|
2162 | return None | |
|
2163 | ||
|
2164 | self.run_ast_nodes(code_ast.body, cell_name, | |
|
2165 | interactivity="last_expr") | |
|
2166 | ||
|
2167 | # Execute any registered post-execution functions. | |
|
2168 | for func, status in self._post_execute.iteritems(): | |
|
2169 | if not status: | |
|
2170 | continue | |
|
2171 | try: | |
|
2172 | func() | |
|
2173 | except: | |
|
2174 | self.showtraceback() | |
|
2175 | # Deactivate failing function | |
|
2176 | self._post_execute[func] = False | |
|
2179 | 2177 | |
|
2180 | 2178 | if store_history: |
|
2181 | 2179 | # Write output to the database. Does nothing unless |
@@ -20,7 +20,10 Authors | |||
|
20 | 20 | #----------------------------------------------------------------------------- |
|
21 | 21 | # stdlib |
|
22 | 22 | import unittest |
|
23 | from cStringIO import StringIO | |
|
24 | ||
|
23 | 25 | from IPython.testing import decorators as dec |
|
26 | from IPython.utils import io | |
|
24 | 27 | |
|
25 | 28 | #----------------------------------------------------------------------------- |
|
26 | 29 | # Tests |
@@ -96,4 +99,11 class InteractiveShellTestCase(unittest.TestCase): | |||
|
96 | 99 | """Errors in prefilter can't crash IPython""" |
|
97 | 100 | ip = get_ipython() |
|
98 | 101 | ip.run_cell('%alias parts echo first %s second %s') |
|
102 | # capture stderr: | |
|
103 | save_err = io.stderr | |
|
104 | io.stderr = StringIO() | |
|
99 | 105 | ip.run_cell('parts 1') |
|
106 | err = io.stderr.getvalue() | |
|
107 | io.stderr = save_err | |
|
108 | self.assertEquals(err.split(':')[0], 'ERROR') | |
|
109 |
General Comments 0
You need to be logged in to leave comments.
Login now