Transform an input cell before parsing it. Static transformations, implemented in IPython.core.inputtransformer2, deal with things like ``%magic`` and ``!system`` commands. These run on all input. Dynamic transformations, for things like unescaped magics and the exit
(self, raw_cell)
| 3523 | return {"ename": etype.__name__, "evalue": str(evalue), "traceback": stb} |
| 3524 | |
| 3525 | def transform_cell(self, raw_cell): |
| 3526 | """Transform an input cell before parsing it. |
| 3527 | |
| 3528 | Static transformations, implemented in IPython.core.inputtransformer2, |
| 3529 | deal with things like ``%magic`` and ``!system`` commands. |
| 3530 | These run on all input. |
| 3531 | Dynamic transformations, for things like unescaped magics and the exit |
| 3532 | autocall, depend on the state of the interpreter. |
| 3533 | These only apply to single line inputs. |
| 3534 | |
| 3535 | These string-based transformations are followed by AST transformations; |
| 3536 | see :meth:`transform_ast`. |
| 3537 | """ |
| 3538 | # Static input transformations |
| 3539 | cell = self.input_transformer_manager.transform_cell(raw_cell) |
| 3540 | |
| 3541 | if len(cell.splitlines()) == 1: |
| 3542 | # Dynamic transformations - only applied for single line commands |
| 3543 | with self.builtin_trap: |
| 3544 | # use prefilter_lines to handle trailing newlines |
| 3545 | # restore trailing newline for ast.parse |
| 3546 | cell = self.prefilter_manager.prefilter_lines(cell) + '\n' |
| 3547 | |
| 3548 | lines = cell.splitlines(keepends=True) |
| 3549 | for transform in self.input_transformers_post: |
| 3550 | lines = transform(lines) |
| 3551 | cell = ''.join(lines) |
| 3552 | |
| 3553 | return cell |
| 3554 | |
| 3555 | def transform_ast(self, node): |
| 3556 | """Apply the AST transformations from self.ast_transformers |