diff options
| author | robot-contrib <[email protected]> | 2022-05-18 00:43:36 +0300 |
|---|---|---|
| committer | robot-contrib <[email protected]> | 2022-05-18 00:43:36 +0300 |
| commit | 9e5f436a8b2a27bcc7802e443ea3ef3e41a82a75 (patch) | |
| tree | 78b522cab9f76336e62064d4d8ff7c897659b20e /contrib/python/ipython/py3/IPython/terminal/magics.py | |
| parent | 8113a823ffca6451bb5ff8f0334560885a939a24 (diff) | |
Update contrib/python/ipython/py3 to 8.3.0
ref:e84342d4d30476f9148137f37fd0c6405fd36f55
Diffstat (limited to 'contrib/python/ipython/py3/IPython/terminal/magics.py')
| -rw-r--r-- | contrib/python/ipython/py3/IPython/terminal/magics.py | 25 |
1 files changed, 13 insertions, 12 deletions
diff --git a/contrib/python/ipython/py3/IPython/terminal/magics.py b/contrib/python/ipython/py3/IPython/terminal/magics.py index 42231c3f803..206ff20a0f8 100644 --- a/contrib/python/ipython/py3/IPython/terminal/magics.py +++ b/contrib/python/ipython/py3/IPython/terminal/magics.py @@ -11,6 +11,7 @@ import sys from IPython.core.error import TryNext, UsageError from IPython.core.magic import Magics, magics_class, line_magic from IPython.lib.clipboard import ClipboardEmpty +from IPython.testing.skipdoctest import skip_doctest from IPython.utils.text import SList, strip_email_quotes from IPython.utils import py3compat @@ -52,7 +53,7 @@ class TerminalMagics(Magics): self.shell.user_ns['pasted_block'] = b self.shell.using_paste_magics = True try: - self.shell.run_cell(b) + self.shell.run_cell(b, store_history=True) finally: self.shell.using_paste_magics = False @@ -83,6 +84,7 @@ class TerminalMagics(Magics): self.shell.set_autoindent() print("Automatic indentation is:",['OFF','ON'][self.shell.autoindent]) + @skip_doctest @line_magic def cpaste(self, parameter_s=''): """Paste & execute a pre-formatted code block from clipboard. @@ -111,9 +113,9 @@ class TerminalMagics(Magics): Shell escapes are not supported (yet). - See also + See Also -------- - paste: automatically pull code from clipboard. + paste : automatically pull code from clipboard. Examples -------- @@ -174,9 +176,9 @@ class TerminalMagics(Magics): IPython statements (magics, shell escapes) are not supported (yet). - See also + See Also -------- - cpaste: manually paste code into terminal until you mark its end. + cpaste : manually paste code into terminal until you mark its end. """ opts, name = self.parse_options(parameter_s, 'rq', mode='string') if 'r' in opts: @@ -191,16 +193,15 @@ class TerminalMagics(Magics): else: error('Could not get text from the clipboard.') return - except ClipboardEmpty: - raise UsageError("The clipboard appears to be empty") + except ClipboardEmpty as e: + raise UsageError("The clipboard appears to be empty") from e # By default, echo back to terminal unless quiet mode is requested if 'q' not in opts: - write = self.shell.write - write(self.shell.pycolorize(block)) - if not block.endswith('\n'): - write('\n') - write("## -- End pasted text --\n") + sys.stdout.write(self.shell.pycolorize(block)) + if not block.endswith("\n"): + sys.stdout.write("\n") + sys.stdout.write("## -- End pasted text --\n") self.store_or_execute(block, name) |
