Skip to content

Commit 9392f24

Browse files
authored
Merge pull request #2 from radarhere/grabclipboard
Simplified code
2 parents 6998f34 + d3205fa commit 9392f24

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/PIL/ImageGrab.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ def grabclipboard():
158158

159159
p = subprocess.run(args, capture_output=True)
160160
if p.returncode != 0:
161-
allowed_errors = [
161+
err = p.stderr
162+
for silent_error in [
162163
# wl-paste, when the clipboard is empty
163164
b"Nothing is copied",
164165
# wl-paste/debian xclip, when an image isn't available
@@ -167,10 +168,9 @@ def grabclipboard():
167168
b"cannot convert",
168169
# xclip, when the clipboard isn't initialized
169170
b"There is no owner",
170-
]
171-
err = p.stderr
172-
if any(e in err for e in allowed_errors):
173-
return None
171+
]:
172+
if err in silent_error:
173+
return None
174174
msg = f"{args[0]} error"
175175
if err:
176176
msg += f": {err.strip().decode()}"

0 commit comments

Comments
 (0)