Add warnings to deprecated CMS profile attributes

This commit is contained in:
Hugo 2019-01-28 11:16:55 +02:00
parent a149c13d2e
commit e1381d2102
3 changed files with 11 additions and 4 deletions

View File

@ -371,8 +371,13 @@ class TestImageCms(PillowTestCase):
self.assertEqual(result, 'XYZ') self.assertEqual(result, 'XYZ')
self.assertIsNone(p.perceptual_rendering_intent_gamut) self.assertIsNone(p.perceptual_rendering_intent_gamut)
self.assertEqual(p.product_copyright,
'Copyright International Color Consortium, 2009') # p.product_copyright
result = self.assert_warning(
DeprecationWarning, getattr, p, "product_copyright"
)
self.assertEqual(result, "Copyright International Color Consortium, 2009")
self.assertEqual(p.product_desc, 'sRGB IEC61966-2-1 black scaled') self.assertEqual(p.product_desc, 'sRGB IEC61966-2-1 black scaled')
self.assertEqual(p.product_description, self.assertEqual(p.product_description,
'sRGB IEC61966-2-1 black scaled') 'sRGB IEC61966-2-1 black scaled')

View File

@ -728,7 +728,7 @@ def getProfileInfo(profile):
# so skipping. # so skipping.
# info was description \r\n\r\n copyright \r\n\r\n K007 tag \r\n\r\n whitepoint # info was description \r\n\r\n copyright \r\n\r\n K007 tag \r\n\r\n whitepoint
description = profile.profile.product_description description = profile.profile.product_description
cpright = profile.profile.product_copyright cpright = profile.profile.copyright
arr = [] arr = []
for elt in (description, cpright): for elt in (description, cpright):
if elt: if elt:
@ -762,7 +762,7 @@ def getProfileCopyright(profile):
# add an extra newline to preserve pyCMS compatibility # add an extra newline to preserve pyCMS compatibility
if not isinstance(profile, ImageCmsProfile): if not isinstance(profile, ImageCmsProfile):
profile = ImageCmsProfile(profile) profile = ImageCmsProfile(profile)
return profile.profile.product_copyright + "\n" return (profile.profile.copyright or "") + "\n"
except (AttributeError, IOError, TypeError, ValueError) as v: except (AttributeError, IOError, TypeError, ValueError) as v:
raise PyCMSError(v) raise PyCMSError(v)

View File

@ -997,6 +997,8 @@ cms_profile_getattr_product_manufacturer(CmsProfileObject* self, void* closure)
static PyObject* static PyObject*
cms_profile_getattr_product_copyright(CmsProfileObject* self, void* closure) 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); return _profile_getattr(self, cmsInfoCopyright);
} }