mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-14 11:26:27 +03:00
Only decode stderr when necessary
This commit is contained in:
parent
cd640e5df2
commit
b81341ae7e
|
@ -157,17 +157,21 @@ def grabclipboard():
|
||||||
raise NotImplementedError(msg)
|
raise NotImplementedError(msg)
|
||||||
|
|
||||||
p = subprocess.run(args, capture_output=True)
|
p = subprocess.run(args, capture_output=True)
|
||||||
err = p.stderr.decode()
|
err = p.stderr
|
||||||
if p.returncode != 0:
|
if p.returncode != 0:
|
||||||
allowed_errors = [
|
allowed_errors = [
|
||||||
"Nothing is copied", # wl-paste, when the clipboard is empty
|
# wl-paste, when the clipboard is empty
|
||||||
"not available", # wl-paste/debian xclip, when an image isn't available
|
b"Nothing is copied",
|
||||||
"cannot convert", # xclip, when an image isn't available
|
# wl-paste/debian xclip, when an image isn't available
|
||||||
"There is no owner", # xclip, when the clipboard isn't initialized
|
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",
|
||||||
]
|
]
|
||||||
if any(e in err for e in allowed_errors):
|
if any(e in err for e in allowed_errors):
|
||||||
return None
|
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)
|
raise ChildProcessError(msg)
|
||||||
|
|
||||||
data = io.BytesIO(p.stdout)
|
data = io.BytesIO(p.stdout)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user