Skip to content

Commit

Permalink
Merge pull request python-pillow#1343 from radarhere/deprecated
Browse files Browse the repository at this point in the history
Removed deprecated code
  • Loading branch information
wiredfool committed Sep 29, 2015
2 parents 29d512a + 71c95c8 commit 89ccf66
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 297 deletions.
58 changes: 8 additions & 50 deletions PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -681,18 +681,9 @@ def tobytes(self, encoder_name="raw", *args):

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"):
"""
Expand Down Expand Up @@ -742,14 +733,8 @@ def frombytes(self, data, decoder_name="raw", *args):
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):
"""
Expand Down Expand Up @@ -1248,27 +1233,8 @@ def histogram(self, mask=None, extrema=None):
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):
"""
Expand Down Expand Up @@ -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):
Expand Down
34 changes: 7 additions & 27 deletions PIL/ImageDraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,38 +90,18 @@ def __init__(self, im, mode=None):
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

Expand Down
40 changes: 0 additions & 40 deletions PIL/ImageFileIO.py

This file was deleted.

22 changes: 3 additions & 19 deletions PIL/ImageFont.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,8 @@ def _load_pilfont_data(self, file, image):
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
Expand Down Expand Up @@ -171,7 +164,7 @@ def font_variant(self, font=None, size=None, index=None, encoding=None):
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.
"""
Expand Down Expand Up @@ -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
Expand All @@ -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:
Expand Down
22 changes: 0 additions & 22 deletions PIL/ImagePalette.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#

import array
import warnings
from PIL import ImageColor


Expand Down Expand Up @@ -80,7 +79,6 @@ def tobytes(self):
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()

Expand Down Expand Up @@ -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:
Expand Down
24 changes: 6 additions & 18 deletions PIL/ImageWin.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
# See the README file for information on usage and redistribution.
#

import warnings
from PIL import Image


Expand Down Expand Up @@ -183,24 +182,13 @@ def tobytes(self):
"""
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)

def tostring(self):
warnings.warn(
'tostring() is deprecated. Please call tobytes() instead.',
DeprecationWarning,
stacklevel=2
)
return self.tobytes()
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.")


##
Expand Down
25 changes: 0 additions & 25 deletions Tests/test_image_offset.py

This file was deleted.

8 changes: 4 additions & 4 deletions Tests/test_imagedraw.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,13 @@ def test_sanity(self):
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()
Expand Down
33 changes: 0 additions & 33 deletions Tests/test_imagefileio.py

This file was deleted.

Loading

0 comments on commit 89ccf66

Please sign in to comment.