From 205731ac5233b6d22f2e7dd1abf4e5f60eb45739 2011-11-21 22:47:49 From: Matt Cottingham Date: 2011-11-21 22:47:49 Subject: [PATCH] Catch clipboard exception in magic_paste and print error message --- diff --git a/IPython/frontend/terminal/interactiveshell.py b/IPython/frontend/terminal/interactiveshell.py index fbfe89c..25bcde3 100644 --- a/IPython/frontend/terminal/interactiveshell.py +++ b/IPython/frontend/terminal/interactiveshell.py @@ -34,7 +34,7 @@ from IPython.testing.skipdoctest import skip_doctest from IPython.utils import py3compat from IPython.utils.terminal import toggle_set_term_title, set_term_title from IPython.utils.process import abbrev_cwd -from IPython.utils.warn import warn +from IPython.utils.warn import warn, error from IPython.utils.text import num_ini_spaces from IPython.utils.traitlets import Int, CBool, Unicode @@ -611,9 +611,16 @@ class TerminalInteractiveShell(InteractiveShell): if opts.has_key('r'): self._rerun_pasted() return - - text = self.shell.hooks.clipboard_get() - block = self._strip_pasted_lines_for_code(text.splitlines()) + try: + text = self.shell.hooks.clipboard_get() + block = self._strip_pasted_lines_for_code(text.splitlines()) + except TryNext as clipboard_exc: + message = getattr(clipboard_exc, 'args') + if message: + error(message) + else: + error('Could not get text from the clipboard.') + return # By default, echo back to terminal unless quiet mode is requested if not opts.has_key('q'):