From d15e4f6a089b785a380b991b5ebc177f0060aac1 2022-05-05 23:45:57 From: Artur Svistunov <18216480+madbird1304@users.noreply.github.com> Date: 2022-05-05 23:45:57 Subject: [PATCH] issue#13073: Made a couple of fixes after testing on Wayland (Gnome) --- diff --git a/IPython/lib/clipboard.py b/IPython/lib/clipboard.py index 5d6630d..1d691a7 100644 --- a/IPython/lib/clipboard.py +++ b/IPython/lib/clipboard.py @@ -1,14 +1,16 @@ """ Utilities for accessing the platform's clipboard. """ - +import os import subprocess from IPython.core.error import TryNext import IPython.utils.py3compat as py3compat + class ClipboardEmpty(ValueError): pass + def win32_clipboard_get(): """ Get the current clipboard's text on Windows. @@ -32,6 +34,7 @@ def win32_clipboard_get(): win32clipboard.CloseClipboard() return text + def osx_clipboard_get() -> str: """ Get the clipboard's text on OS X. """ @@ -43,6 +46,7 @@ def osx_clipboard_get() -> str: text = py3compat.decode(bytes_) return text + def tkinter_clipboard_get(): """ Get the clipboard's text using Tkinter. @@ -77,13 +81,18 @@ def wayland_clipboard_get(): try: with subprocess.Popen(["wl-paste"], stdout=subprocess.PIPE) as p: - raw, _ = p.communicate() + raw, err = p.communicate() + if p.wait(): + raise TryNext(err) except FileNotFoundError as e: - raise ClipboardEmpty( + raise TryNext( "Getting text from the clipboard under Wayland requires the wl-clipboard " "extension: https://github.com/bugaevc/wl-clipboard" ) from e + if not raw: + raise ClipboardEmpty + try: text = py3compat.decode(raw) except UnicodeDecodeError as e: