mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-08 13:53:21 +03:00
Merge pull request #3615 from hugovk/imagecms-deprecations
Add warnings to deprecated CMS profile attributes
This commit is contained in:
commit
f707affbde
|
@ -309,7 +309,7 @@ class TestImageCms(PillowTestCase):
|
|||
2: (False, False, True),
|
||||
3: (False, False, True)
|
||||
})
|
||||
self.assertEqual(p.color_space, 'RGB')
|
||||
|
||||
self.assertIsNone(p.colorant_table)
|
||||
self.assertIsNone(p.colorant_table_out)
|
||||
self.assertIsNone(p.colorimetric_intent)
|
||||
|
@ -361,16 +361,9 @@ class TestImageCms(PillowTestCase):
|
|||
(5000.722328847392,))
|
||||
self.assertEqual(p.model,
|
||||
'IEC 61966-2-1 Default RGB Colour Space - sRGB')
|
||||
self.assertEqual(p.pcs, 'XYZ')
|
||||
|
||||
self.assertIsNone(p.perceptual_rendering_intent_gamut)
|
||||
self.assertEqual(p.product_copyright,
|
||||
'Copyright International Color Consortium, 2009')
|
||||
self.assertEqual(p.product_desc, 'sRGB IEC61966-2-1 black scaled')
|
||||
self.assertEqual(p.product_description,
|
||||
'sRGB IEC61966-2-1 black scaled')
|
||||
self.assertEqual(p.product_manufacturer, '')
|
||||
self.assertEqual(
|
||||
p.product_model, 'IEC 61966-2-1 Default RGB Colour Space - sRGB')
|
||||
|
||||
self.assertEqual(
|
||||
p.profile_description, 'sRGB IEC61966-2-1 black scaled')
|
||||
self.assertEqual(
|
||||
|
@ -393,6 +386,40 @@ class TestImageCms(PillowTestCase):
|
|||
'Reference Viewing Condition in IEC 61966-2-1')
|
||||
self.assertEqual(p.xcolor_space, 'RGB ')
|
||||
|
||||
def test_deprecations(self):
|
||||
self.skip_missing()
|
||||
o = ImageCms.getOpenProfile(SRGB)
|
||||
p = o.profile
|
||||
|
||||
def helper_deprecated(attr, expected):
|
||||
result = self.assert_warning(DeprecationWarning, getattr, p, attr)
|
||||
self.assertEqual(result, expected)
|
||||
|
||||
# p.color_space
|
||||
helper_deprecated("color_space", "RGB")
|
||||
|
||||
# p.pcs
|
||||
helper_deprecated("pcs", "XYZ")
|
||||
|
||||
# p.product_copyright
|
||||
helper_deprecated(
|
||||
"product_copyright", "Copyright International Color Consortium, 2009"
|
||||
)
|
||||
|
||||
# p.product_desc
|
||||
helper_deprecated("product_desc", "sRGB IEC61966-2-1 black scaled")
|
||||
|
||||
# p.product_description
|
||||
helper_deprecated("product_description", "sRGB IEC61966-2-1 black scaled")
|
||||
|
||||
# p.product_manufacturer
|
||||
helper_deprecated("product_manufacturer", "")
|
||||
|
||||
# p.product_model
|
||||
helper_deprecated(
|
||||
"product_model", "IEC 61966-2-1 Default RGB Colour Space - sRGB"
|
||||
)
|
||||
|
||||
def test_profile_typesafety(self):
|
||||
""" Profile init type safety
|
||||
|
||||
|
|
|
@ -79,6 +79,26 @@ PILLOW_VERSION constant
|
|||
``PILLOW_VERSION`` has been deprecated and will be removed in the next
|
||||
major release. Use ``__version__`` instead.
|
||||
|
||||
ImageCms.CmsProfile attributes
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
.. deprecated:: 3.2.0
|
||||
|
||||
Some attributes in ``ImageCms.CmsProfile`` are deprecated. From 6.0.0, they issue a
|
||||
``DeprecationWarning``:
|
||||
|
||||
======================== ===============================
|
||||
Deprecated Use instead
|
||||
======================== ===============================
|
||||
``color_space`` Padded ``xcolor_space``
|
||||
``pcs`` Padded ``connection_space``
|
||||
``product_copyright`` Unicode ``copyright``
|
||||
``product_desc`` Unicode ``profile_description``
|
||||
``product_description`` Unicode ``profile_description``
|
||||
``product_manufacturer`` Unicode ``manufacturer``
|
||||
``product_model`` Unicode ``model``
|
||||
======================== ===============================
|
||||
|
||||
Removed features
|
||||
----------------
|
||||
|
||||
|
|
|
@ -132,21 +132,21 @@ can be easily displayed in a chromaticity diagram, for example).
|
|||
|
||||
.. py:attribute:: manufacturer
|
||||
|
||||
The (english) display string for the device manufacturer (see
|
||||
The (English) display string for the device manufacturer (see
|
||||
9.2.22 of ICC.1:2010).
|
||||
|
||||
:type: :py:class:`unicode` or ``None``
|
||||
|
||||
.. py:attribute:: model
|
||||
|
||||
The (english) display string for the device model of the device
|
||||
The (English) display string for the device model of the device
|
||||
for which this profile is created (see 9.2.23 of ICC.1:2010).
|
||||
|
||||
:type: :py:class:`unicode` or ``None``
|
||||
|
||||
.. py:attribute:: profile_description
|
||||
|
||||
The (english) display string for the profile description (see
|
||||
The (English) display string for the profile description (see
|
||||
9.2.41 of ICC.1:2010).
|
||||
|
||||
:type: :py:class:`unicode` or ``None``
|
||||
|
@ -269,14 +269,14 @@ can be easily displayed in a chromaticity diagram, for example).
|
|||
|
||||
.. py:attribute:: viewing_condition
|
||||
|
||||
The (english) display string for the viewing conditions (see
|
||||
The (English) display string for the viewing conditions (see
|
||||
9.2.48 of ICC.1:2010).
|
||||
|
||||
:type: :py:class:`unicode` or ``None``
|
||||
|
||||
.. py:attribute:: screening_description
|
||||
|
||||
The (english) display string for the screening conditions.
|
||||
The (English) display string for the screening conditions.
|
||||
|
||||
This tag was available in ICC 3.2, but it is removed from
|
||||
version 4.
|
||||
|
|
|
@ -99,6 +99,24 @@ version.
|
|||
|
||||
Use ``PIL.__version__`` instead.
|
||||
|
||||
ImageCms.CmsProfile attributes
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Some attributes in ``ImageCms.CmsProfile`` have been deprecated since Pillow 3.2.0. From
|
||||
6.0.0, they issue a ``DeprecationWarning``:
|
||||
|
||||
======================== ===============================
|
||||
Deprecated Use instead
|
||||
======================== ===============================
|
||||
``color_space`` Padded ``xcolor_space``
|
||||
``pcs`` Padded ``connection_space``
|
||||
``product_copyright`` Unicode ``copyright``
|
||||
``product_desc`` Unicode ``profile_description``
|
||||
``product_description`` Unicode ``profile_description``
|
||||
``product_manufacturer`` Unicode ``manufacturer``
|
||||
``product_model`` Unicode ``model``
|
||||
======================== ===============================
|
||||
|
||||
MIME type improvements
|
||||
^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
|
@ -686,11 +686,11 @@ def getProfileName(profile):
|
|||
# // name was "%s - %s" (model, manufacturer) || Description ,
|
||||
# // but if the Model and Manufacturer were the same or the model
|
||||
# // was long, Just the model, in 1.x
|
||||
model = profile.profile.product_model
|
||||
manufacturer = profile.profile.product_manufacturer
|
||||
model = profile.profile.model
|
||||
manufacturer = profile.profile.manufacturer
|
||||
|
||||
if not (model or manufacturer):
|
||||
return profile.profile.product_description + "\n"
|
||||
return (profile.profile.profile_description or "") + "\n"
|
||||
if not manufacturer or len(model) > 30:
|
||||
return model + "\n"
|
||||
return "%s - %s\n" % (model, manufacturer)
|
||||
|
@ -727,8 +727,8 @@ def getProfileInfo(profile):
|
|||
# Python, not C. the white point bits weren't working well,
|
||||
# so skipping.
|
||||
# info was description \r\n\r\n copyright \r\n\r\n K007 tag \r\n\r\n whitepoint
|
||||
description = profile.profile.product_description
|
||||
cpright = profile.profile.product_copyright
|
||||
description = profile.profile.profile_description
|
||||
cpright = profile.profile.copyright
|
||||
arr = []
|
||||
for elt in (description, cpright):
|
||||
if elt:
|
||||
|
@ -762,7 +762,7 @@ def getProfileCopyright(profile):
|
|||
# add an extra newline to preserve pyCMS compatibility
|
||||
if not isinstance(profile, ImageCmsProfile):
|
||||
profile = ImageCmsProfile(profile)
|
||||
return profile.profile.product_copyright + "\n"
|
||||
return (profile.profile.copyright or "") + "\n"
|
||||
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||
raise PyCMSError(v)
|
||||
|
||||
|
@ -790,7 +790,7 @@ def getProfileManufacturer(profile):
|
|||
# add an extra newline to preserve pyCMS compatibility
|
||||
if not isinstance(profile, ImageCmsProfile):
|
||||
profile = ImageCmsProfile(profile)
|
||||
return profile.profile.product_manufacturer + "\n"
|
||||
return (profile.profile.manufacturer or "") + "\n"
|
||||
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||
raise PyCMSError(v)
|
||||
|
||||
|
@ -819,7 +819,7 @@ def getProfileModel(profile):
|
|||
# add an extra newline to preserve pyCMS compatibility
|
||||
if not isinstance(profile, ImageCmsProfile):
|
||||
profile = ImageCmsProfile(profile)
|
||||
return profile.profile.product_model + "\n"
|
||||
return (profile.profile.model or "") + "\n"
|
||||
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||
raise PyCMSError(v)
|
||||
|
||||
|
@ -848,7 +848,7 @@ def getProfileDescription(profile):
|
|||
# add an extra newline to preserve pyCMS compatibility
|
||||
if not isinstance(profile, ImageCmsProfile):
|
||||
profile = ImageCmsProfile(profile)
|
||||
return profile.profile.product_description + "\n"
|
||||
return (profile.profile.profile_description or "") + "\n"
|
||||
except (AttributeError, IOError, TypeError, ValueError) as v:
|
||||
raise PyCMSError(v)
|
||||
|
||||
|
|
|
@ -967,6 +967,8 @@ _profile_getattr(CmsProfileObject* self, cmsInfoType field)
|
|||
static PyObject*
|
||||
cms_profile_getattr_product_desc(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"product_desc is deprecated. Use Unicode profile_description instead.", 1);
|
||||
// description was Description != 'Copyright' || or "%s - %s" (manufacturer, model) in 1.x
|
||||
return _profile_getattr(self, cmsInfoDescription);
|
||||
}
|
||||
|
@ -976,24 +978,32 @@ cms_profile_getattr_product_desc(CmsProfileObject* self, void* closure)
|
|||
static PyObject*
|
||||
cms_profile_getattr_product_description(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"product_description is deprecated. Use Unicode profile_description instead.", 1);
|
||||
return _profile_getattr(self, cmsInfoDescription);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
cms_profile_getattr_product_model(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"product_model is deprecated. Use Unicode model instead.", 1);
|
||||
return _profile_getattr(self, cmsInfoModel);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
cms_profile_getattr_product_manufacturer(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"product_manufacturer is deprecated. Use Unicode manufacturer instead.", 1);
|
||||
return _profile_getattr(self, cmsInfoManufacturer);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
cms_profile_getattr_product_copyright(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"product_copyright is deprecated. Use Unicode copyright instead.", 1);
|
||||
return _profile_getattr(self, cmsInfoCopyright);
|
||||
}
|
||||
|
||||
|
@ -1006,12 +1016,16 @@ cms_profile_getattr_rendering_intent(CmsProfileObject* self, void* closure)
|
|||
static PyObject*
|
||||
cms_profile_getattr_pcs(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"pcs is deprecated. Use padded connection_space instead.", 1);
|
||||
return PyUnicode_DecodeFSDefault(findICmode(cmsGetPCS(self->profile)));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
cms_profile_getattr_color_space(CmsProfileObject* self, void* closure)
|
||||
{
|
||||
PyErr_WarnEx(PyExc_DeprecationWarning,
|
||||
"color_space is deprecated. Use padded xcolor_space instead.", 1);
|
||||
return PyUnicode_DecodeFSDefault(findICmode(cmsGetColorSpace(self->profile)));
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user