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