mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 01:16:16 +03:00
Restore fromstring & tostring aliases in 3.x
This commit is contained in:
parent
525de9b14a
commit
c59c6609f3
43
PIL/Image.py
43
PIL/Image.py
|
@ -538,15 +538,14 @@ class Image:
|
|||
|
||||
return b"".join(data)
|
||||
|
||||
if bytes is str:
|
||||
# Declare tostring as alias to tobytes
|
||||
def tostring(self, *args, **kw):
|
||||
warnings.warn(
|
||||
'tostring() is deprecated. Please call tobytes() instead.',
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return self.tobytes(*args, **kw)
|
||||
# Declare tostring as alias to tobytes
|
||||
def tostring(self, *args, **kw):
|
||||
warnings.warn(
|
||||
'tostring() is deprecated. Please call tobytes() instead.',
|
||||
DeprecationWarning,
|
||||
stacklevel=2,
|
||||
)
|
||||
return self.tobytes(*args, **kw)
|
||||
|
||||
##
|
||||
# Returns the image converted to an X11 bitmap. This method
|
||||
|
@ -595,11 +594,10 @@ class Image:
|
|||
if s[1] != 0:
|
||||
raise ValueError("cannot decode image data")
|
||||
|
||||
if bytes is str:
|
||||
# Declare fromstring as alias to frombytes
|
||||
def fromstring(self, *args, **kw):
|
||||
warnings.warn('fromstring() is deprecated. Please call frombytes() instead.', DeprecationWarning)
|
||||
return self.frombytes(*args, **kw)
|
||||
def fromstring(self, *args, **kw):
|
||||
""" Deprecated alias to frombytes """
|
||||
warnings.warn('fromstring() is deprecated. Please call frombytes() instead.', DeprecationWarning)
|
||||
return self.frombytes(*args, **kw)
|
||||
|
||||
##
|
||||
# Allocates storage for the image and loads the pixel data. In
|
||||
|
@ -1814,15 +1812,14 @@ def frombytes(mode, size, data, decoder_name="raw", *args):
|
|||
im.frombytes(data, decoder_name, args)
|
||||
return im
|
||||
|
||||
if bytes is str:
|
||||
# Declare fromstring as an alias for frombytes
|
||||
def fromstring(*args, **kw):
|
||||
warnings.warn(
|
||||
'fromstring() is deprecated. Please call frombytes() instead.',
|
||||
DeprecationWarning,
|
||||
stacklevel=2
|
||||
)
|
||||
return frombytes(*args, **kw)
|
||||
def fromstring(*args, **kw):
|
||||
" Deprecated alias to frombytes "
|
||||
warnings.warn(
|
||||
'fromstring() is deprecated. Please call frombytes() instead.',
|
||||
DeprecationWarning,
|
||||
stacklevel=2
|
||||
)
|
||||
return frombytes(*args, **kw)
|
||||
|
||||
##
|
||||
# (New in 1.1.4) Creates an image memory referencing pixel data in a
|
||||
|
|
|
@ -49,9 +49,8 @@ class ImagePalette:
|
|||
return self.palette
|
||||
return array.array("B", self.palette).tostring()
|
||||
|
||||
if bytes is str:
|
||||
# Declare tostring as an alias for tobytes
|
||||
tostring = tobytes
|
||||
# Declare tostring as an alias for tobytes
|
||||
tostring = tobytes
|
||||
|
||||
def getcolor(self, color):
|
||||
# experimental: given an rgb tuple, allocate palette entry
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
# See the README file for information on usage and redistribution.
|
||||
#
|
||||
|
||||
import warnings
|
||||
from . import Image
|
||||
|
||||
##
|
||||
|
@ -167,9 +168,24 @@ class Dib:
|
|||
def tobytes(self):
|
||||
return self.image.tobytes()
|
||||
|
||||
if bytes is str:
|
||||
tostring = tobytes
|
||||
fromstring = frombytes
|
||||
##
|
||||
# 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()
|
||||
|
||||
##
|
||||
# Create a Window with the given title size.
|
||||
|
|
|
@ -497,9 +497,7 @@ static PyMethodDef pyCMSdll_methods[] = {
|
|||
|
||||
{"profile_open", cms_profile_open, 1},
|
||||
{"profile_frombytes", cms_profile_fromstring, 1},
|
||||
#if PY_VERSION_HEX < 0x03000000
|
||||
{"profile_fromstring", cms_profile_fromstring, 1},
|
||||
#endif
|
||||
|
||||
/* profile and transform functions */
|
||||
{"buildTransform", buildTransform, 1},
|
||||
|
|
|
@ -224,10 +224,8 @@ static struct PyMethodDef methods[] = {
|
|||
{"releasedc", (PyCFunction)_releasedc, 1},
|
||||
{"frombytes", (PyCFunction)_frombytes, 1},
|
||||
{"tobytes", (PyCFunction)_tobytes, 1},
|
||||
#if PY_VERSION_HEX < 0x03000000
|
||||
{"fromstring", (PyCFunction)_frombytes, 1},
|
||||
{"tostring", (PyCFunction)_tobytes, 1},
|
||||
#endif
|
||||
{NULL, NULL} /* sentinel */
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user