Merge pull request #1343 from radarhere/deprecated

Removed deprecated code
This commit is contained in:
wiredfool 2015-09-29 15:38:34 +01:00
commit 89ccf66ff7
14 changed files with 34 additions and 296 deletions

View File

@ -681,18 +681,9 @@ class Image(object):
return b"".join(data) return b"".join(data)
# Declare tostring as alias to tobytes
def tostring(self, *args, **kw): def tostring(self, *args, **kw):
"""Deprecated alias to tobytes. raise Exception("tostring() has been removed. " +
"Please call tobytes() instead.")
.. deprecated:: 2.0
"""
warnings.warn(
'tostring() is deprecated. Please call tobytes() instead.',
DeprecationWarning,
stacklevel=2,
)
return self.tobytes(*args, **kw)
def tobitmap(self, name="image"): def tobitmap(self, name="image"):
""" """
@ -742,14 +733,8 @@ class Image(object):
raise ValueError("cannot decode image data") raise ValueError("cannot decode image data")
def fromstring(self, *args, **kw): def fromstring(self, *args, **kw):
"""Deprecated alias to frombytes. raise Exception("fromstring() has been removed. " +
"Please call frombytes() instead.")
.. deprecated:: 2.0
"""
warnings.warn(
'fromstring() is deprecated. Please call frombytes() instead.',
DeprecationWarning)
return self.frombytes(*args, **kw)
def load(self): def load(self):
""" """
@ -1248,27 +1233,8 @@ class Image(object):
return self.im.histogram() return self.im.histogram()
def offset(self, xoffset, yoffset=None): def offset(self, xoffset, yoffset=None):
""" raise Exception("offset() has been removed. " +
.. deprecated:: 2.0 "Please call ImageChops.offset() instead.")
.. note:: New code should use :py:func:`PIL.ImageChops.offset`.
Returns a copy of the image where the data has been offset by the given
distances. Data wraps around the edges. If **yoffset** is omitted, it
is assumed to be equal to **xoffset**.
:param xoffset: The horizontal distance.
:param yoffset: The vertical distance. If omitted, both
distances are set to the same value.
:returns: An :py:class:`~PIL.Image.Image` object.
"""
if warnings:
warnings.warn(
"'offset' is deprecated; use 'ImageChops.offset' instead",
DeprecationWarning, stacklevel=2
)
from PIL import ImageChops
return ImageChops.offset(self, xoffset, yoffset)
def paste(self, im, box=None, mask=None): def paste(self, im, box=None, mask=None):
""" """
@ -2083,16 +2049,8 @@ def frombytes(mode, size, data, decoder_name="raw", *args):
def fromstring(*args, **kw): def fromstring(*args, **kw):
"""Deprecated alias to frombytes. raise Exception("fromstring() has been removed. " +
"Please call frombytes() instead.")
.. deprecated:: 2.0
"""
warnings.warn(
'fromstring() is deprecated. Please call frombytes() instead.',
DeprecationWarning,
stacklevel=2
)
return frombytes(*args, **kw)
def frombuffer(mode, size, data, decoder_name="raw", *args): def frombuffer(mode, size, data, decoder_name="raw", *args):

View File

@ -90,38 +90,18 @@ class ImageDraw(object):
self.fill = 0 self.fill = 0
self.font = None self.font = None
##
# Set the default pen color.
def setink(self, ink): def setink(self, ink):
# compatibility raise Exception("setink() has been removed. " +
if warnings: "Please use keyword arguments instead.")
warnings.warn(
"'setink' is deprecated; use keyword arguments instead",
DeprecationWarning, stacklevel=2
)
if isStringType(ink):
ink = ImageColor.getcolor(ink, self.mode)
if self.palette and not isinstance(ink, numbers.Number):
ink = self.palette.getcolor(ink)
self.ink = self.draw.draw_ink(ink, self.mode)
##
# Set the default background color.
def setfill(self, onoff): def setfill(self, onoff):
# compatibility raise Exception("setfill() has been removed. " +
if warnings: "Please use keyword arguments instead.")
warnings.warn(
"'setfill' is deprecated; use keyword arguments instead",
DeprecationWarning, stacklevel=2
)
self.fill = onoff
##
# Set the default font.
def setfont(self, font): def setfont(self, font):
if warnings:
warnings.warn("setfont() is deprecated. " +
"Please set the attribute directly instead.")
# compatibility # compatibility
self.font = font self.font = font

View File

@ -1,40 +0,0 @@
#
# The Python Imaging Library.
# $Id$
#
# kludge to get basic ImageFileIO functionality
#
# History:
# 1998-08-06 fl Recreated
#
# Copyright (c) Secret Labs AB 1998-2002.
#
# See the README file for information on usage and redistribution.
#
"""
The **ImageFileIO** module can be used to read an image from a
socket, or any other stream device.
Deprecated. New code should use the :class:`PIL.ImageFile.Parser`
class in the :mod:`PIL.ImageFile` module instead.
.. seealso:: modules :class:`PIL.ImageFile.Parser`
"""
from io import BytesIO
class ImageFileIO(BytesIO):
def __init__(self, fp):
"""
Adds buffering to a stream file object, in order to
provide **seek** and **tell** methods required
by the :func:`PIL.Image.Image.open` method. The stream object must
implement **read** and **close** methods.
:param fp: Stream file handle.
.. seealso:: modules :func:`PIL.Image.open`
"""
data = fp.read()
BytesIO.__init__(self, data)

View File

@ -121,15 +121,8 @@ class ImageFont(object):
class FreeTypeFont(object): class FreeTypeFont(object):
"FreeType font wrapper (requires _imagingft service)" "FreeType font wrapper (requires _imagingft service)"
def __init__(self, font=None, size=10, index=0, encoding="", file=None): def __init__(self, font=None, size=10, index=0, encoding=""):
# FIXME: use service provider instead # FIXME: use service provider instead
if file:
if warnings:
warnings.warn(
'file parameter deprecated, '
'please use font parameter instead.',
DeprecationWarning)
font = file
self.path = font self.path = font
self.size = size self.size = size
@ -171,7 +164,7 @@ class FreeTypeFont(object):
using any specified arguments to override the settings. using any specified arguments to override the settings.
Parameters are identical to the parameters used to initialize this Parameters are identical to the parameters used to initialize this
object, minus the deprecated 'file' argument. object.
:return: A FreeTypeFont object. :return: A FreeTypeFont object.
""" """
@ -225,7 +218,7 @@ def load(filename):
return f return f
def truetype(font=None, size=10, index=0, encoding="", filename=None): def truetype(font=None, size=10, index=0, encoding=""):
""" """
Load a TrueType or OpenType font file, and create a font object. Load a TrueType or OpenType font file, and create a font object.
This function loads a font object from the given file, and creates This function loads a font object from the given file, and creates
@ -243,19 +236,10 @@ def truetype(font=None, size=10, index=0, encoding="", filename=None):
Symbol), "ADOB" (Adobe Standard), "ADBE" (Adobe Expert), Symbol), "ADOB" (Adobe Standard), "ADBE" (Adobe Expert),
and "armn" (Apple Roman). See the FreeType documentation and "armn" (Apple Roman). See the FreeType documentation
for more information. for more information.
:param filename: Deprecated. Please use font instead.
:return: A font object. :return: A font object.
:exception IOError: If the file could not be read. :exception IOError: If the file could not be read.
""" """
if filename:
if warnings:
warnings.warn(
'filename parameter deprecated, '
'please use font parameter instead.',
DeprecationWarning)
font = filename
try: try:
return FreeTypeFont(font, size, index, encoding) return FreeTypeFont(font, size, index, encoding)
except IOError: except IOError:

View File

@ -17,7 +17,6 @@
# #
import array import array
import warnings
from PIL import ImageColor from PIL import ImageColor
@ -80,7 +79,6 @@ class ImagePalette(object):
return self.palette return self.palette
arr = array.array("B", self.palette) arr = array.array("B", self.palette)
if hasattr(arr, 'tobytes'): if hasattr(arr, 'tobytes'):
# py3k has a tobytes, tostring is deprecated.
return arr.tobytes() return arr.tobytes()
return arr.tostring() return arr.tostring()
@ -149,26 +147,6 @@ def raw(rawmode, data):
# -------------------------------------------------------------------- # --------------------------------------------------------------------
# Factories # Factories
def _make_linear_lut(black, white):
warnings.warn(
'_make_linear_lut() is deprecated. '
'Please call make_linear_lut() instead.',
DeprecationWarning,
stacklevel=2
)
return make_linear_lut(black, white)
def _make_gamma_lut(exp):
warnings.warn(
'_make_gamma_lut() is deprecated. '
'Please call make_gamma_lut() instead.',
DeprecationWarning,
stacklevel=2
)
return make_gamma_lut(exp)
def make_linear_lut(black, white): def make_linear_lut(black, white):
lut = [] lut = []
if black == 0: if black == 0:

View File

@ -17,7 +17,6 @@
# See the README file for information on usage and redistribution. # See the README file for information on usage and redistribution.
# #
import warnings
from PIL import Image from PIL import Image
@ -183,24 +182,13 @@ class Dib(object):
""" """
return self.image.tobytes() return self.image.tobytes()
##
# Deprecated aliases to frombytes & tobytes.
def fromstring(self, *args, **kw): def fromstring(self, *args, **kw):
warnings.warn( raise Exception("fromstring() has been removed. " +
'fromstring() is deprecated. Please call frombytes() instead.', "Please use frombytes() instead.")
DeprecationWarning,
stacklevel=2
)
return self.frombytes(*args, **kw)
def tostring(self): def tostring(self, *args, **kw):
warnings.warn( raise Exception("tostring() has been removed. " +
'tostring() is deprecated. Please call tobytes() instead.', "Please use tobytes() instead.")
DeprecationWarning,
stacklevel=2
)
return self.tobytes()
## ##

View File

@ -1,25 +0,0 @@
from helper import unittest, PillowTestCase, hopper
class TestImageOffset(PillowTestCase):
def test_offset(self):
im1 = hopper()
im2 = self.assert_warning(DeprecationWarning, lambda: im1.offset(10))
self.assertEqual(im1.getpixel((0, 0)), im2.getpixel((10, 10)))
im2 = self.assert_warning(
DeprecationWarning, lambda: im1.offset(10, 20))
self.assertEqual(im1.getpixel((0, 0)), im2.getpixel((10, 20)))
im2 = self.assert_warning(
DeprecationWarning, lambda: im1.offset(20, 20))
self.assertEqual(im1.getpixel((0, 0)), im2.getpixel((20, 20)))
if __name__ == '__main__':
unittest.main()
# End of file

View File

@ -44,13 +44,13 @@ class TestImageDraw(PillowTestCase):
draw.polygon(list(range(100))) draw.polygon(list(range(100)))
draw.rectangle(list(range(4))) draw.rectangle(list(range(4)))
def test_deprecated(self): def test_removed_methods(self):
im = hopper().copy() im = hopper()
draw = ImageDraw.Draw(im) draw = ImageDraw.Draw(im)
self.assert_warning(DeprecationWarning, lambda: draw.setink(0)) self.assertRaises(Exception, lambda: draw.setink(0))
self.assert_warning(DeprecationWarning, lambda: draw.setfill(0)) self.assertRaises(Exception, lambda: draw.setfill(0))
def test_mode_mismatch(self): def test_mode_mismatch(self):
im = hopper("RGB").copy() im = hopper("RGB").copy()

View File

@ -1,33 +0,0 @@
from helper import unittest, PillowTestCase, hopper, tostring
from PIL import Image
from PIL import ImageFileIO
class TestImageFileIo(PillowTestCase):
def test_fileio(self):
class DumbFile(object):
def __init__(self, data):
self.data = data
def read(self, bytes=None):
assert(bytes is None)
return self.data
def close(self):
pass
im1 = hopper()
io = ImageFileIO.ImageFileIO(DumbFile(tostring(im1, "PPM")))
im2 = Image.open(io)
self.assert_image_equal(im1, im2)
if __name__ == '__main__':
unittest.main()
# End of file

View File

@ -88,11 +88,6 @@ try:
self._render(f) self._render(f)
self._clean() self._clean()
def test_font_old_parameters(self):
self.assert_warning(
DeprecationWarning,
lambda: ImageFont.truetype(filename=FONT_PATH, size=FONT_SIZE))
def _render(self, font): def _render(self, font):
txt = "Hello World!" txt = "Hello World!"
ttf = ImageFont.truetype(font, FONT_SIZE) ttf = ImageFont.truetype(font, FONT_SIZE)
@ -228,11 +223,11 @@ try:
font, orientation=orientation) font, orientation=orientation)
# Original font # Original font
draw.setfont(font) draw.font = font
box_size_a = draw.textsize(word) box_size_a = draw.textsize(word)
# Rotated font # Rotated font
draw.setfont(transposed_font) draw.font = transposed_font
box_size_b = draw.textsize(word) box_size_b = draw.textsize(word)
# Check (w,h) of box a is (h,w) of box b # Check (w,h) of box a is (h,w) of box b
@ -250,11 +245,11 @@ try:
font, orientation=orientation) font, orientation=orientation)
# Original font # Original font
draw.setfont(font) draw.font = font
box_size_a = draw.textsize(word) box_size_a = draw.textsize(word)
# Rotated font # Rotated font
draw.setfont(transposed_font) draw.font = transposed_font
box_size_b = draw.textsize(word) box_size_b = draw.textsize(word)
# Check boxes a and b are same size # Check boxes a and b are same size

View File

@ -90,27 +90,6 @@ class TestImagePalette(PillowTestCase):
self.assertEqual(lut[191], 60) self.assertEqual(lut[191], 60)
self.assertEqual(lut[255], 255) self.assertEqual(lut[255], 255)
def test_private_make_linear_lut_warning(self):
# Arrange
from PIL.ImagePalette import _make_linear_lut
black = 0
white = 255
# Act / Assert
self.assert_warning(
DeprecationWarning,
lambda: _make_linear_lut(black, white))
def test_private_make_gamma_lut_warning(self):
# Arrange
from PIL.ImagePalette import _make_gamma_lut
exp = 5
# Act / Assert
self.assert_warning(
DeprecationWarning,
lambda: _make_gamma_lut(exp))
def test_rawmode_valueerrors(self): def test_rawmode_valueerrors(self):
# Arrange # Arrange
from PIL.ImagePalette import raw from PIL.ImagePalette import raw

View File

@ -107,16 +107,14 @@ class TestImageWinDib(PillowTestCase):
# Confirm they're the same # Confirm they're the same
self.assertEqual(dib1.tobytes(), dib2.tobytes()) self.assertEqual(dib1.tobytes(), dib2.tobytes())
def test_dib_fromstring_tostring_deprecated(self): def test_removed_methods(self):
# Arrange # Arrange
im = hopper() im = hopper()
dib = ImageWin.Dib(im) dib = ImageWin.Dib(im)
test_buffer = dib.tobytes()
# Act/Assert # Act/Assert
self.assert_warning(DeprecationWarning, dib.tostring) self.assertRaises(Exception, dib.tostring)
self.assert_warning(DeprecationWarning, self.assertRaises(Exception, lambda: dib.fromstring(test_buffer))
lambda: dib.fromstring(test_buffer))
if __name__ == '__main__': if __name__ == '__main__':

View File

@ -64,15 +64,6 @@ can be found here.
.. intentionally skipped documenting this because it's deprecated .. intentionally skipped documenting this because it's deprecated
:mod:`ImageFileIO` Module
-------------------------
.. automodule:: PIL.ImageFileIO
:members:
:undoc-members:
:show-inheritance:
:mod:`ImageShow` Module :mod:`ImageShow` Module
----------------------- -----------------------

View File

@ -278,21 +278,6 @@ these methods. Do not mix the old and new calling conventions.
:rtype: :py:class:`~PIL.ImageDraw.Draw` :rtype: :py:class:`~PIL.ImageDraw.Draw`
.. py:method:: PIL.ImageDraw.Draw.setink(ink)
.. deprecated:: 1.1.5
Sets the color to use for subsequent draw and fill operations.
.. py:method:: PIL.ImageDraw.Draw.setfill(fill)
.. deprecated:: 1.1.5
Sets the fill mode.
If the mode is 0, subsequently drawn shapes (like polygons and rectangles)
are outlined. If the mode is 1, they are filled.
.. py:method:: PIL.ImageDraw.Draw.setfont(font) .. py:method:: PIL.ImageDraw.Draw.setfont(font)
.. deprecated:: 1.1.5 .. deprecated:: 1.1.5