From 71c95c8e5f3bba1845444a246d04646825e6bab3 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 19 Sep 2015 21:36:19 +1000 Subject: [PATCH] Restored deprecated methods with errors instead --- PIL/Image.py | 17 +++++++++++++++++ PIL/ImageDraw.py | 8 ++++++++ PIL/ImageWin.py | 8 ++++++++ Tests/test_imagedraw.py | 8 ++++++++ Tests/test_imagewin.py | 9 +++++++++ 5 files changed, 50 insertions(+) diff --git a/PIL/Image.py b/PIL/Image.py index be00132b2..c08a1252d 100644 --- a/PIL/Image.py +++ b/PIL/Image.py @@ -681,6 +681,10 @@ class Image(object): return b"".join(data) + def tostring(self, *args, **kw): + raise Exception("tostring() has been removed. " + + "Please call tobytes() instead.") + def tobitmap(self, name="image"): """ Returns the image converted to an X11 bitmap. @@ -728,6 +732,10 @@ class Image(object): if s[1] != 0: raise ValueError("cannot decode image data") + def fromstring(self, *args, **kw): + raise Exception("fromstring() has been removed. " + + "Please call frombytes() instead.") + def load(self): """ Allocates storage for the image and loads the pixel data. In @@ -1224,6 +1232,10 @@ class Image(object): return self.im.histogram(extrema) return self.im.histogram() + def offset(self, xoffset, yoffset=None): + raise Exception("offset() has been removed. " + + "Please call ImageChops.offset() instead.") + def paste(self, im, box=None, mask=None): """ Pastes another image into this image. The box argument is either @@ -2034,6 +2046,11 @@ def frombytes(mode, size, data, decoder_name="raw", *args): return im +def fromstring(*args, **kw): + raise Exception("fromstring() has been removed. " + + "Please call frombytes() instead.") + + def frombuffer(mode, size, data, decoder_name="raw", *args): """ Creates an image memory referencing pixel data in a byte buffer. diff --git a/PIL/ImageDraw.py b/PIL/ImageDraw.py index b7260c14b..9e154f236 100644 --- a/PIL/ImageDraw.py +++ b/PIL/ImageDraw.py @@ -90,6 +90,14 @@ class ImageDraw(object): self.fill = 0 self.font = None + def setink(self, ink): + raise Exception("setink() has been removed. " + + "Please use keyword arguments instead.") + + def setfill(self, onoff): + raise Exception("setfill() has been removed. " + + "Please use keyword arguments instead.") + def setfont(self, font): if warnings: warnings.warn("setfont() is deprecated. " + diff --git a/PIL/ImageWin.py b/PIL/ImageWin.py index 85b463afc..58894d604 100644 --- a/PIL/ImageWin.py +++ b/PIL/ImageWin.py @@ -182,6 +182,14 @@ class Dib(object): """ return self.image.tobytes() + def fromstring(self, *args, **kw): + raise Exception("fromstring() has been removed. " + + "Please use frombytes() instead.") + + def tostring(self, *args, **kw): + raise Exception("tostring() has been removed. " + + "Please use tobytes() instead.") + ## # Create a Window with the given title size. diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index 5a85f1a90..3074fd7fa 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -44,6 +44,14 @@ class TestImageDraw(PillowTestCase): draw.polygon(list(range(100))) draw.rectangle(list(range(4))) + def test_removed_methods(self): + im = hopper() + + draw = ImageDraw.Draw(im) + + self.assertRaises(Exception, lambda: draw.setink(0)) + self.assertRaises(Exception, lambda: draw.setfill(0)) + def test_mode_mismatch(self): im = hopper("RGB").copy() diff --git a/Tests/test_imagewin.py b/Tests/test_imagewin.py index e719513d7..14cc2c7e3 100644 --- a/Tests/test_imagewin.py +++ b/Tests/test_imagewin.py @@ -107,6 +107,15 @@ class TestImageWinDib(PillowTestCase): # Confirm they're the same self.assertEqual(dib1.tobytes(), dib2.tobytes()) + def test_removed_methods(self): + # Arrange + im = hopper() + dib = ImageWin.Dib(im) + + # Act/Assert + self.assertRaises(Exception, dib.tostring) + self.assertRaises(Exception, lambda: dib.fromstring(test_buffer)) + if __name__ == '__main__': unittest.main()