From 13ab784c51d3d813a7fa4771f8a40429acb2a4fe Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 28 Dec 2019 22:59:09 +1100 Subject: [PATCH] Raise error if grabclipboard is used not on macOS or Windows --- Tests/test_imagegrab.py | 5 ++++- src/PIL/ImageGrab.py | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py index 0e29ea693..e3905cb3d 100644 --- a/Tests/test_imagegrab.py +++ b/Tests/test_imagegrab.py @@ -26,7 +26,7 @@ class TestImageGrab: def test_grabclipboard(self): if sys.platform == "darwin": subprocess.call(["screencapture", "-cx"]) - else: + elif sys.platform == "win32": p = subprocess.Popen(["powershell", "-command", "-"], stdin=subprocess.PIPE) p.stdin.write( b"""[Reflection.Assembly]::LoadWithPartialName("System.Drawing") @@ -35,6 +35,9 @@ $bmp = New-Object Drawing.Bitmap 200, 200 [Windows.Forms.Clipboard]::SetImage($bmp)""" ) p.communicate() + else: + self.assertRaises(NotImplementedError, ImageGrab.grabclipboard) + return im = ImageGrab.grabclipboard() assert_image(im, im.mode, im.size) diff --git a/src/PIL/ImageGrab.py b/src/PIL/ImageGrab.py index cbb284d9e..0355ed482 100644 --- a/src/PIL/ImageGrab.py +++ b/src/PIL/ImageGrab.py @@ -110,3 +110,6 @@ def grabclipboard(): return BmpImagePlugin.DibImageFile(io.BytesIO(data)) return data + + else: + raise NotImplementedError("grabclipboard is macOS and Windows only")