Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rearranged code #1

Merged
merged 2 commits into from
Jan 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions src/PIL/ImageGrab.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,17 +157,21 @@ def grabclipboard():
raise NotImplementedError(msg)

p = subprocess.run(args, capture_output=True)
err = p.stderr.decode()
if p.returncode != 0:
allowed_errors = [
"Nothing is copied", # wl-paste, when the clipboard is empty
"not available", # wl-paste/debian xclip, when an image isn't available
"cannot convert", # xclip, when an image isn't available
"There is no owner", # xclip, when the clipboard isn't initialized
# wl-paste, when the clipboard is empty
b"Nothing is copied",
# wl-paste/debian xclip, when an image isn't available
b"not available",
# xclip, when an image isn't available
b"cannot convert",
# xclip, when the clipboard isn't initialized
b"There is no owner",
]
err = p.stderr
if any(e in err for e in allowed_errors):
return None
msg = f"{args[0]} error: {err.strip() if err else 'Unknown error'}"
msg = f"{args[0]} error: {err.strip().decode() if err else 'Unknown error'}"
raise ChildProcessError(msg)

data = io.BytesIO(p.stdout)
Expand Down