Add warnings to deprecated CMS profile attributes

This commit is contained in:
Hugo 2019-01-28 11:10:38 +02:00
parent 7d157bd825
commit a149c13d2e
3 changed files with 10 additions and 3 deletions

View File

@ -376,7 +376,12 @@ class TestImageCms(PillowTestCase):
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, '')
# p.product_manufacturer
result = self.assert_warning(
DeprecationWarning, getattr, p, "product_manufacturer"
)
self.assertEqual(result, "")
# p.product_model
result = self.assert_warning(DeprecationWarning, getattr, p, "product_model")

View File

@ -687,7 +687,7 @@ def getProfileName(profile):
# // but if the Model and Manufacturer were the same or the model
# // was long, Just the model, in 1.x
model = profile.profile.model
manufacturer = profile.profile.product_manufacturer
manufacturer = profile.profile.manufacturer
if not (model or manufacturer):
return profile.profile.product_description + "\n"
@ -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)

View File

@ -989,6 +989,8 @@ cms_profile_getattr_product_model(CmsProfileObject* self, void* closure)
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);
}