Skip to content

Commit

Permalink
Restored deprecated methods with errors instead
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Sep 19, 2015
1 parent 5835c1e commit 71c95c8
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 0 deletions.
17 changes: 17 additions & 0 deletions PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,10 @@ def tobytes(self, encoder_name="raw", *args):

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.
Expand Down Expand Up @@ -728,6 +732,10 @@ def frombytes(self, data, decoder_name="raw", *args):
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
Expand Down Expand Up @@ -1224,6 +1232,10 @@ def histogram(self, mask=None, extrema=None):
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
Expand Down Expand Up @@ -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.
Expand Down
8 changes: 8 additions & 0 deletions PIL/ImageDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ def __init__(self, im, mode=None):
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. " +
Expand Down
8 changes: 8 additions & 0 deletions PIL/ImageWin.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,14 @@ def tobytes(self):
"""
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.
Expand Down
8 changes: 8 additions & 0 deletions Tests/test_imagedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,14 @@ def test_sanity(self):
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()

Expand Down
9 changes: 9 additions & 0 deletions Tests/test_imagewin.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,15 @@ def test_dib_frombytes_tobytes_roundtrip(self):
# 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()
Expand Down

0 comments on commit 71c95c8

Please sign in to comment.