Show More
@@ -1,14 +1,16 b'' | |||
|
1 | 1 | """ Utilities for accessing the platform's clipboard. |
|
2 | 2 | """ |
|
3 | ||
|
3 | import os | |
|
4 | 4 | import subprocess |
|
5 | 5 | |
|
6 | 6 | from IPython.core.error import TryNext |
|
7 | 7 | import IPython.utils.py3compat as py3compat |
|
8 | 8 | |
|
9 | ||
|
9 | 10 | class ClipboardEmpty(ValueError): |
|
10 | 11 | pass |
|
11 | 12 | |
|
13 | ||
|
12 | 14 | def win32_clipboard_get(): |
|
13 | 15 | """ Get the current clipboard's text on Windows. |
|
14 | 16 | |
@@ -32,6 +34,7 b' def win32_clipboard_get():' | |||
|
32 | 34 | win32clipboard.CloseClipboard() |
|
33 | 35 | return text |
|
34 | 36 | |
|
37 | ||
|
35 | 38 | def osx_clipboard_get() -> str: |
|
36 | 39 | """ Get the clipboard's text on OS X. |
|
37 | 40 | """ |
@@ -43,6 +46,7 b' def osx_clipboard_get() -> str:' | |||
|
43 | 46 | text = py3compat.decode(bytes_) |
|
44 | 47 | return text |
|
45 | 48 | |
|
49 | ||
|
46 | 50 | def tkinter_clipboard_get(): |
|
47 | 51 | """ Get the clipboard's text using Tkinter. |
|
48 | 52 | |
@@ -77,13 +81,18 b' def wayland_clipboard_get():' | |||
|
77 | 81 | |
|
78 | 82 | try: |
|
79 | 83 | with subprocess.Popen(["wl-paste"], stdout=subprocess.PIPE) as p: |
|
80 |
raw, |
|
|
84 | raw, err = p.communicate() | |
|
85 | if p.wait(): | |
|
86 | raise TryNext(err) | |
|
81 | 87 | except FileNotFoundError as e: |
|
82 |
raise |
|
|
88 | raise TryNext( | |
|
83 | 89 | "Getting text from the clipboard under Wayland requires the wl-clipboard " |
|
84 | 90 | "extension: https://github.com/bugaevc/wl-clipboard" |
|
85 | 91 | ) from e |
|
86 | 92 | |
|
93 | if not raw: | |
|
94 | raise ClipboardEmpty | |
|
95 | ||
|
87 | 96 | try: |
|
88 | 97 | text = py3compat.decode(raw) |
|
89 | 98 | except UnicodeDecodeError as e: |
General Comments 0
You need to be logged in to leave comments.
Login now