mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-11 00:32:27 +03:00
deprecate IptcImagePlugin.{dump,i,PAD}
This commit is contained in:
parent
6c4b47dc46
commit
fa4b3776f0
|
@ -87,24 +87,28 @@ def test_i():
|
||||||
c = b"a"
|
c = b"a"
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
|
with pytest.warns(DeprecationWarning):
|
||||||
ret = IptcImagePlugin.i(c)
|
ret = IptcImagePlugin.i(c)
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert ret == 97
|
assert ret == 97
|
||||||
|
|
||||||
|
|
||||||
def test_dump():
|
def test_dump(monkeypatch):
|
||||||
# Arrange
|
# Arrange
|
||||||
c = b"abc"
|
c = b"abc"
|
||||||
# Temporarily redirect stdout
|
# Temporarily redirect stdout
|
||||||
old_stdout = sys.stdout
|
mystdout = StringIO()
|
||||||
sys.stdout = mystdout = StringIO()
|
monkeypatch.setattr(sys, "stdout", mystdout)
|
||||||
|
|
||||||
# Act
|
# Act
|
||||||
|
with pytest.warns(DeprecationWarning):
|
||||||
IptcImagePlugin.dump(c)
|
IptcImagePlugin.dump(c)
|
||||||
|
|
||||||
# Reset stdout
|
|
||||||
sys.stdout = old_stdout
|
|
||||||
|
|
||||||
# Assert
|
# Assert
|
||||||
assert mystdout.getvalue() == "61 62 63 \n"
|
assert mystdout.getvalue() == "61 62 63 \n"
|
||||||
|
|
||||||
|
|
||||||
|
def test_pad_deprecation():
|
||||||
|
with pytest.warns(DeprecationWarning):
|
||||||
|
assert IptcImagePlugin.PAD == b"\0\0\0\0"
|
||||||
|
|
|
@ -22,25 +22,38 @@ import tempfile
|
||||||
from . import Image, ImageFile
|
from . import Image, ImageFile
|
||||||
from ._binary import i16be as i16
|
from ._binary import i16be as i16
|
||||||
from ._binary import i32be as i32
|
from ._binary import i32be as i32
|
||||||
|
from ._deprecate import deprecate
|
||||||
|
|
||||||
COMPRESSION = {1: "raw", 5: "jpeg"}
|
COMPRESSION = {1: "raw", 5: "jpeg"}
|
||||||
|
|
||||||
PAD = b"\0\0\0\0"
|
|
||||||
|
def __getattr__(name):
|
||||||
|
if name == "PAD":
|
||||||
|
deprecate("IptcImagePlugin.PAD", 12)
|
||||||
|
return b"\0\0\0\0"
|
||||||
|
msg = f"module '{__name__}' has no attribute '{name}'"
|
||||||
|
raise AttributeError(msg)
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
# Helpers
|
# Helpers
|
||||||
|
|
||||||
|
|
||||||
|
def _i(c):
|
||||||
|
return i32((b"\0\0\0\0" + c)[-4:])
|
||||||
|
|
||||||
|
|
||||||
def _i8(c: int | bytes) -> int:
|
def _i8(c: int | bytes) -> int:
|
||||||
return c if isinstance(c, int) else c[0]
|
return c if isinstance(c, int) else c[0]
|
||||||
|
|
||||||
|
|
||||||
def i(c):
|
def i(c):
|
||||||
return i32((PAD + c)[-4:])
|
deprecate("IptcImagePlugin.i", 12)
|
||||||
|
return _i(c)
|
||||||
|
|
||||||
|
|
||||||
def dump(c):
|
def dump(c):
|
||||||
|
deprecate("IptcImagePlugin.dump", 12)
|
||||||
for i in c:
|
for i in c:
|
||||||
print("%02x" % _i8(i), end=" ")
|
print("%02x" % _i8(i), end=" ")
|
||||||
print()
|
print()
|
||||||
|
@ -56,7 +69,7 @@ class IptcImageFile(ImageFile.ImageFile):
|
||||||
format_description = "IPTC/NAA"
|
format_description = "IPTC/NAA"
|
||||||
|
|
||||||
def getint(self, key):
|
def getint(self, key):
|
||||||
return i(self.info[key])
|
return _i(self.info[key])
|
||||||
|
|
||||||
def field(self):
|
def field(self):
|
||||||
#
|
#
|
||||||
|
@ -80,7 +93,7 @@ class IptcImageFile(ImageFile.ImageFile):
|
||||||
elif size == 128:
|
elif size == 128:
|
||||||
size = 0
|
size = 0
|
||||||
elif size > 128:
|
elif size > 128:
|
||||||
size = i(self.fp.read(size - 128))
|
size = _i(self.fp.read(size - 128))
|
||||||
else:
|
else:
|
||||||
size = i16(s, 3)
|
size = i16(s, 3)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user