API change/revert: Bytes should be returned as a single byte string, not a tuple of integers

This commit is contained in:
wiredfool 2016-06-26 12:06:56 +01:00
parent a64c1674a1
commit c50503a14d
2 changed files with 3 additions and 5 deletions

View File

@ -544,8 +544,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
self.tagtype[tag] = 2 self.tagtype[tag] = 2
if self.tagtype[tag] == 7 and bytes is not str: if self.tagtype[tag] == 7 and bytes is not str:
values = [value.encode("ascii", 'replace') if isinstance(value, str) else value values = [value.encode("ascii", 'replace') if isinstance(value, str) else value]
for value in values]
values = tuple(info.cvt_enum(value) for value in values) values = tuple(info.cvt_enum(value) for value in values)
@ -604,8 +603,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
@_register_loader(1, 1) # Basic type, except for the legacy API. @_register_loader(1, 1) # Basic type, except for the legacy API.
def load_byte(self, data, legacy_api=True): def load_byte(self, data, legacy_api=True):
return (data if legacy_api else return data
tuple(map(ord, data) if bytes is str else data))
@_register_writer(1) # Basic type, except for the legacy API. @_register_writer(1) # Basic type, except for the legacy API.
def write_byte(self, data): def write_byte(self, data):

View File

@ -287,7 +287,7 @@ class TestFileTiff(PillowTestCase):
ifd = TiffImagePlugin.ImageFileDirectory_v2() ifd = TiffImagePlugin.ImageFileDirectory_v2()
data = b"abc" data = b"abc"
ret = ifd.load_byte(data, legacy_api) ret = ifd.load_byte(data, legacy_api)
self.assertEqual(ret, b"abc" if legacy_api else (97, 98, 99)) self.assertEqual(ret, b"abc")
def test_load_string(self): def test_load_string(self):
ifd = TiffImagePlugin.ImageFileDirectory_v2() ifd = TiffImagePlugin.ImageFileDirectory_v2()