mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-27 09:44:31 +03:00
Reorder load_* parameters to pass master tests
This commit is contained in:
parent
05348d4f8f
commit
4adbc9735c
|
@ -329,7 +329,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
||||||
data = self._tagdata[tag]
|
data = self._tagdata[tag]
|
||||||
typ = self.tagtype[tag]
|
typ = self.tagtype[tag]
|
||||||
size, handler = self._load_dispatch[typ]
|
size, handler = self._load_dispatch[typ]
|
||||||
self[tag] = handler(self, self.legacy_api, data) # check type
|
self[tag] = handler(self, data, self.legacy_api) # check type
|
||||||
val = self._tags_v2[tag]
|
val = self._tags_v2[tag]
|
||||||
if self.legacy_api and not isinstance(val, (tuple, bytes)):
|
if self.legacy_api and not isinstance(val, (tuple, bytes)):
|
||||||
val = val,
|
val = val,
|
||||||
|
@ -422,7 +422,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
||||||
idx, fmt, name = idx_fmt_name
|
idx, fmt, name = idx_fmt_name
|
||||||
TYPES[idx] = name
|
TYPES[idx] = name
|
||||||
size = struct.calcsize("=" + fmt)
|
size = struct.calcsize("=" + fmt)
|
||||||
_load_dispatch[idx] = size, lambda self, legacy_api, data: (
|
_load_dispatch[idx] = size, lambda self, data, legacy_api=True: (
|
||||||
self._unpack("{0}{1}".format(len(data) // size, fmt), data))
|
self._unpack("{0}{1}".format(len(data) // size, fmt), data))
|
||||||
_write_dispatch[idx] = lambda self, *values: (
|
_write_dispatch[idx] = lambda self, *values: (
|
||||||
b"".join(self._pack(fmt, value) for value in values))
|
b"".join(self._pack(fmt, value) for value in values))
|
||||||
|
@ -433,7 +433,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
||||||
(9, "l", "signed long"), (11, "f", "float"), (12, "d", "double")]))
|
(9, "l", "signed long"), (11, "f", "float"), (12, "d", "double")]))
|
||||||
|
|
||||||
@_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, legacy_api, data):
|
def load_byte(self, data, legacy_api=True):
|
||||||
return (data if legacy_api else
|
return (data if legacy_api else
|
||||||
tuple(map(ord, data) if bytes is str else data))
|
tuple(map(ord, data) if bytes is str else data))
|
||||||
|
|
||||||
|
@ -442,7 +442,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@_register_loader(2, 1)
|
@_register_loader(2, 1)
|
||||||
def load_string(self, legacy_api, data):
|
def load_string(self, data, legacy_api=True):
|
||||||
if data.endswith(b"\0"):
|
if data.endswith(b"\0"):
|
||||||
data = data[:-1]
|
data = data[:-1]
|
||||||
return data.decode("latin-1", "replace")
|
return data.decode("latin-1", "replace")
|
||||||
|
@ -455,7 +455,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
||||||
return b"" + value.encode('ascii', 'replace') + b"\0"
|
return b"" + value.encode('ascii', 'replace') + b"\0"
|
||||||
|
|
||||||
@_register_loader(5, 8)
|
@_register_loader(5, 8)
|
||||||
def load_rational(self, legacy_api, data):
|
def load_rational(self, data, legacy_api=True):
|
||||||
vals = self._unpack("{0}L".format(len(data) // 4), data)
|
vals = self._unpack("{0}L".format(len(data) // 4), data)
|
||||||
combine = lambda a, b: (a, b) if legacy_api else a / b
|
combine = lambda a, b: (a, b) if legacy_api else a / b
|
||||||
return tuple(combine(num, denom)
|
return tuple(combine(num, denom)
|
||||||
|
@ -467,7 +467,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
||||||
for frac in values)
|
for frac in values)
|
||||||
|
|
||||||
@_register_loader(7, 1)
|
@_register_loader(7, 1)
|
||||||
def load_undefined(self, legacy_api, data):
|
def load_undefined(self, data, legacy_api=True):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
@_register_writer(7)
|
@_register_writer(7)
|
||||||
|
@ -475,7 +475,7 @@ class ImageFileDirectory_v2(collections.MutableMapping):
|
||||||
return value
|
return value
|
||||||
|
|
||||||
@_register_loader(10, 8)
|
@_register_loader(10, 8)
|
||||||
def load_signed_rational(self, legacy_api, data):
|
def load_signed_rational(self, data, legacy_api=True):
|
||||||
vals = self._unpack("{0}l".format(len(data) // 4), data)
|
vals = self._unpack("{0}l".format(len(data) // 4), data)
|
||||||
combine = lambda a, b: (a, b) if legacy_api else a / b
|
combine = lambda a, b: (a, b) if legacy_api else a / b
|
||||||
return tuple(combine(num, denom)
|
return tuple(combine(num, denom)
|
||||||
|
@ -678,7 +678,7 @@ class ImageFileDirectory_v1(ImageFileDirectory_v2):
|
||||||
typ = self.tagtype[tag]
|
typ = self.tagtype[tag]
|
||||||
size, handler = self._load_dispatch[typ]
|
size, handler = self._load_dispatch[typ]
|
||||||
for legacy in (False, True):
|
for legacy in (False, True):
|
||||||
self._setitem(tag, handler(self, legacy, data), legacy)
|
self._setitem(tag, handler(self, data, legacy), legacy)
|
||||||
val = self._tags_v1[tag]
|
val = self._tags_v1[tag]
|
||||||
if not isinstance(val, (tuple, bytes)):
|
if not isinstance(val, (tuple, bytes)):
|
||||||
val = val,
|
val = val,
|
||||||
|
|
|
@ -255,25 +255,25 @@ class TestFileTiff(PillowTestCase):
|
||||||
for legacy_api in [False, True]:
|
for legacy_api in [False, True]:
|
||||||
ifd = TiffImagePlugin.ImageFileDirectory_v2()
|
ifd = TiffImagePlugin.ImageFileDirectory_v2()
|
||||||
data = b"abc"
|
data = b"abc"
|
||||||
ret = ifd.load_byte(legacy_api, data)
|
ret = ifd.load_byte(data, legacy_api)
|
||||||
self.assertEqual(ret, b"abc" if legacy_api else (97, 98, 99))
|
self.assertEqual(ret, b"abc" if legacy_api else (97, 98, 99))
|
||||||
|
|
||||||
def test_load_string(self):
|
def test_load_string(self):
|
||||||
ifd = TiffImagePlugin.ImageFileDirectory_v2()
|
ifd = TiffImagePlugin.ImageFileDirectory_v2()
|
||||||
data = b"abc\0"
|
data = b"abc\0"
|
||||||
ret = ifd.load_string(False, data)
|
ret = ifd.load_string(data, False)
|
||||||
self.assertEqual(ret, "abc")
|
self.assertEqual(ret, "abc")
|
||||||
|
|
||||||
def test_load_float(self):
|
def test_load_float(self):
|
||||||
ifd = TiffImagePlugin.ImageFileDirectory_v2()
|
ifd = TiffImagePlugin.ImageFileDirectory_v2()
|
||||||
data = b"abcdabcd"
|
data = b"abcdabcd"
|
||||||
ret = ifd.load_float(False, data)
|
ret = ifd.load_float(data, False)
|
||||||
self.assertEqual(ret, (1.6777999408082104e+22, 1.6777999408082104e+22))
|
self.assertEqual(ret, (1.6777999408082104e+22, 1.6777999408082104e+22))
|
||||||
|
|
||||||
def test_load_double(self):
|
def test_load_double(self):
|
||||||
ifd = TiffImagePlugin.ImageFileDirectory_v2()
|
ifd = TiffImagePlugin.ImageFileDirectory_v2()
|
||||||
data = b"abcdefghabcdefgh"
|
data = b"abcdefghabcdefgh"
|
||||||
ret = ifd.load_double(False, data)
|
ret = ifd.load_double(data, False)
|
||||||
self.assertEqual(ret, (8.540883223036124e+194, 8.540883223036124e+194))
|
self.assertEqual(ret, (8.540883223036124e+194, 8.540883223036124e+194))
|
||||||
|
|
||||||
def test_seek(self):
|
def test_seek(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user