mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Merge pull request #1343 from radarhere/deprecated
Removed deprecated code
This commit is contained in:
commit
89ccf66ff7
58
PIL/Image.py
58
PIL/Image.py
|
@ -681,18 +681,9 @@ class Image(object):
|
|||
|
||||
return b"".join(data)
|
||||
|
||||
# Declare tostring as alias to tobytes
|
||||
def tostring(self, *args, **kw):
|
||||
"""Deprecated alias to tobytes.
|
||||
|
||||
.. deprecated:: 2.0
|
||||
"""
|
||||
warnings.warn(
|
||||
'tostring() is deprecated. Please call tobytes() instead.',
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return self.tobytes(*args, **kw)
|
||||
raise Exception("tostring() has been removed. " +
|
||||
"Please call tobytes() instead.")
|
||||
|
||||
def tobitmap(self, name="image"):
|
||||
"""
|
||||
|
@ -742,14 +733,8 @@ class Image(object):
|
|||
raise ValueError("cannot decode image data")
|
||||
|
||||
def fromstring(self, *args, **kw):
|
||||
"""Deprecated alias to frombytes.
|
||||
|
||||
.. deprecated:: 2.0
|
||||
"""
|
||||
warnings.warn(
|
||||
'fromstring() is deprecated. Please call frombytes() instead.',
|
||||
DeprecationWarning)
|
||||
return self.frombytes(*args, **kw)
|
||||
raise Exception("fromstring() has been removed. " +
|
||||
"Please call frombytes() instead.")
|
||||
|
||||
def load(self):
|
||||
"""
|
||||
|
@ -1248,27 +1233,8 @@ class Image(object):
|
|||
return self.im.histogram()
|
||||
|
||||
def offset(self, xoffset, yoffset=None):
|
||||
"""
|
||||
.. deprecated:: 2.0
|
||||
|
||||
.. 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)
|
||||
raise Exception("offset() has been removed. " +
|
||||
"Please call ImageChops.offset() instead.")
|
||||
|
||||
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):
|
||||
"""Deprecated alias to frombytes.
|
||||
|
||||
.. deprecated:: 2.0
|
||||
"""
|
||||
warnings.warn(
|
||||
'fromstring() is deprecated. Please call frombytes() instead.',
|
||||
DeprecationWarning,
|
||||
stacklevel=2
|
||||
)
|
||||
return frombytes(*args, **kw)
|
||||
raise Exception("fromstring() has been removed. " +
|
||||
"Please call frombytes() instead.")
|
||||
|
||||
|
||||
def frombuffer(mode, size, data, decoder_name="raw", *args):
|
||||
|
|
|
@ -90,38 +90,18 @@ class ImageDraw(object):
|
|||
self.fill = 0
|
||||
self.font = None
|
||||
|
||||
##
|
||||
# Set the default pen color.
|
||||
|
||||
def setink(self, ink):
|
||||
# compatibility
|
||||
if warnings:
|
||||
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.
|
||||
raise Exception("setink() has been removed. " +
|
||||
"Please use keyword arguments instead.")
|
||||
|
||||
def setfill(self, onoff):
|
||||
# compatibility
|
||||
if warnings:
|
||||
warnings.warn(
|
||||
"'setfill' is deprecated; use keyword arguments instead",
|
||||
DeprecationWarning, stacklevel=2
|
||||
)
|
||||
self.fill = onoff
|
||||
|
||||
##
|
||||
# Set the default font.
|
||||
raise Exception("setfill() has been removed. " +
|
||||
"Please use keyword arguments instead.")
|
||||
|
||||
def setfont(self, font):
|
||||
if warnings:
|
||||
warnings.warn("setfont() is deprecated. " +
|
||||
"Please set the attribute directly instead.")
|
||||
# compatibility
|
||||
self.font = font
|
||||
|
||||
|
|
|
@ -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)
|
|
@ -121,15 +121,8 @@ class ImageFont(object):
|
|||
class FreeTypeFont(object):
|
||||
"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
|
||||
if file:
|
||||
if warnings:
|
||||
warnings.warn(
|
||||
'file parameter deprecated, '
|
||||
'please use font parameter instead.',
|
||||
DeprecationWarning)
|
||||
font = file
|
||||
|
||||
self.path = font
|
||||
self.size = size
|
||||
|
@ -171,7 +164,7 @@ class FreeTypeFont(object):
|
|||
using any specified arguments to override the settings.
|
||||
|
||||
Parameters are identical to the parameters used to initialize this
|
||||
object, minus the deprecated 'file' argument.
|
||||
object.
|
||||
|
||||
:return: A FreeTypeFont object.
|
||||
"""
|
||||
|
@ -225,7 +218,7 @@ def load(filename):
|
|||
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.
|
||||
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),
|
||||
and "armn" (Apple Roman). See the FreeType documentation
|
||||
for more information.
|
||||
:param filename: Deprecated. Please use font instead.
|
||||
:return: A font object.
|
||||
: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:
|
||||
return FreeTypeFont(font, size, index, encoding)
|
||||
except IOError:
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
#
|
||||
|
||||
import array
|
||||
import warnings
|
||||
from PIL import ImageColor
|
||||
|
||||
|
||||
|
@ -80,7 +79,6 @@ class ImagePalette(object):
|
|||
return self.palette
|
||||
arr = array.array("B", self.palette)
|
||||
if hasattr(arr, 'tobytes'):
|
||||
# py3k has a tobytes, tostring is deprecated.
|
||||
return arr.tobytes()
|
||||
return arr.tostring()
|
||||
|
||||
|
@ -149,26 +147,6 @@ def raw(rawmode, data):
|
|||
# --------------------------------------------------------------------
|
||||
# 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):
|
||||
lut = []
|
||||
if black == 0:
|
||||
|
|
|
@ -17,7 +17,6 @@
|
|||
# See the README file for information on usage and redistribution.
|
||||
#
|
||||
|
||||
import warnings
|
||||
from PIL import Image
|
||||
|
||||
|
||||
|
@ -183,24 +182,13 @@ class Dib(object):
|
|||
"""
|
||||
return self.image.tobytes()
|
||||
|
||||
##
|
||||
# Deprecated aliases to frombytes & tobytes.
|
||||
|
||||
def fromstring(self, *args, **kw):
|
||||
warnings.warn(
|
||||
'fromstring() is deprecated. Please call frombytes() instead.',
|
||||
DeprecationWarning,
|
||||
stacklevel=2
|
||||
)
|
||||
return self.frombytes(*args, **kw)
|
||||
raise Exception("fromstring() has been removed. " +
|
||||
"Please use frombytes() instead.")
|
||||
|
||||
def tostring(self):
|
||||
warnings.warn(
|
||||
'tostring() is deprecated. Please call tobytes() instead.',
|
||||
DeprecationWarning,
|
||||
stacklevel=2
|
||||
)
|
||||
return self.tobytes()
|
||||
def tostring(self, *args, **kw):
|
||||
raise Exception("tostring() has been removed. " +
|
||||
"Please use tobytes() instead.")
|
||||
|
||||
|
||||
##
|
||||
|
|
|
@ -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
|
|
@ -44,13 +44,13 @@ class TestImageDraw(PillowTestCase):
|
|||
draw.polygon(list(range(100)))
|
||||
draw.rectangle(list(range(4)))
|
||||
|
||||
def test_deprecated(self):
|
||||
im = hopper().copy()
|
||||
def test_removed_methods(self):
|
||||
im = hopper()
|
||||
|
||||
draw = ImageDraw.Draw(im)
|
||||
|
||||
self.assert_warning(DeprecationWarning, lambda: draw.setink(0))
|
||||
self.assert_warning(DeprecationWarning, lambda: draw.setfill(0))
|
||||
self.assertRaises(Exception, lambda: draw.setink(0))
|
||||
self.assertRaises(Exception, lambda: draw.setfill(0))
|
||||
|
||||
def test_mode_mismatch(self):
|
||||
im = hopper("RGB").copy()
|
||||
|
|
|
@ -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
|
|
@ -88,11 +88,6 @@ try:
|
|||
self._render(f)
|
||||
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):
|
||||
txt = "Hello World!"
|
||||
ttf = ImageFont.truetype(font, FONT_SIZE)
|
||||
|
@ -228,11 +223,11 @@ try:
|
|||
font, orientation=orientation)
|
||||
|
||||
# Original font
|
||||
draw.setfont(font)
|
||||
draw.font = font
|
||||
box_size_a = draw.textsize(word)
|
||||
|
||||
# Rotated font
|
||||
draw.setfont(transposed_font)
|
||||
draw.font = transposed_font
|
||||
box_size_b = draw.textsize(word)
|
||||
|
||||
# Check (w,h) of box a is (h,w) of box b
|
||||
|
@ -250,11 +245,11 @@ try:
|
|||
font, orientation=orientation)
|
||||
|
||||
# Original font
|
||||
draw.setfont(font)
|
||||
draw.font = font
|
||||
box_size_a = draw.textsize(word)
|
||||
|
||||
# Rotated font
|
||||
draw.setfont(transposed_font)
|
||||
draw.font = transposed_font
|
||||
box_size_b = draw.textsize(word)
|
||||
|
||||
# Check boxes a and b are same size
|
||||
|
|
|
@ -90,27 +90,6 @@ class TestImagePalette(PillowTestCase):
|
|||
self.assertEqual(lut[191], 60)
|
||||
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):
|
||||
# Arrange
|
||||
from PIL.ImagePalette import raw
|
||||
|
|
|
@ -107,16 +107,14 @@ class TestImageWinDib(PillowTestCase):
|
|||
# Confirm they're the same
|
||||
self.assertEqual(dib1.tobytes(), dib2.tobytes())
|
||||
|
||||
def test_dib_fromstring_tostring_deprecated(self):
|
||||
def test_removed_methods(self):
|
||||
# Arrange
|
||||
im = hopper()
|
||||
dib = ImageWin.Dib(im)
|
||||
test_buffer = dib.tobytes()
|
||||
|
||||
# Act/Assert
|
||||
self.assert_warning(DeprecationWarning, dib.tostring)
|
||||
self.assert_warning(DeprecationWarning,
|
||||
lambda: dib.fromstring(test_buffer))
|
||||
self.assertRaises(Exception, dib.tostring)
|
||||
self.assertRaises(Exception, lambda: dib.fromstring(test_buffer))
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
|
@ -64,15 +64,6 @@ can be found here.
|
|||
|
||||
.. intentionally skipped documenting this because it's deprecated
|
||||
|
||||
:mod:`ImageFileIO` Module
|
||||
-------------------------
|
||||
|
||||
.. automodule:: PIL.ImageFileIO
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
||||
|
||||
|
||||
:mod:`ImageShow` Module
|
||||
-----------------------
|
||||
|
||||
|
|
|
@ -278,21 +278,6 @@ these methods. Do not mix the old and new calling conventions.
|
|||
|
||||
: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)
|
||||
|
||||
.. deprecated:: 1.1.5
|
||||
|
|
Loading…
Reference in New Issue
Block a user