Skip to content

Commit 1522b3f

Browse files
authored
Merge pull request #1 from radarhere/grabclipboard
Rearranged code
2 parents cd640e5 + d2d9240 commit 1522b3f

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/PIL/ImageGrab.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,21 @@ def grabclipboard():
157157
raise NotImplementedError(msg)
158158

159159
p = subprocess.run(args, capture_output=True)
160-
err = p.stderr.decode()
161160
if p.returncode != 0:
162161
allowed_errors = [
163-
"Nothing is copied", # wl-paste, when the clipboard is empty
164-
"not available", # wl-paste/debian xclip, when an image isn't available
165-
"cannot convert", # xclip, when an image isn't available
166-
"There is no owner", # xclip, when the clipboard isn't initialized
162+
# wl-paste, when the clipboard is empty
163+
b"Nothing is copied",
164+
# wl-paste/debian xclip, when an image isn't available
165+
b"not available",
166+
# xclip, when an image isn't available
167+
b"cannot convert",
168+
# xclip, when the clipboard isn't initialized
169+
b"There is no owner",
167170
]
171+
err = p.stderr
168172
if any(e in err for e in allowed_errors):
169173
return None
170-
msg = f"{args[0]} error: {err.strip() if err else 'Unknown error'}"
174+
msg = f"{args[0]} error: {err.strip().decode() if err else 'Unknown error'}"
171175
raise ChildProcessError(msg)
172176

173177
data = io.BytesIO(p.stdout)

0 commit comments

Comments
 (0)