mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-02-03 21:24:31 +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"
|
||||
|
||||
# Act
|
||||
ret = IptcImagePlugin.i(c)
|
||||
with pytest.warns(DeprecationWarning):
|
||||
ret = IptcImagePlugin.i(c)
|
||||
|
||||
# Assert
|
||||
assert ret == 97
|
||||
|
||||
|
||||
def test_dump():
|
||||
def test_dump(monkeypatch):
|
||||
# Arrange
|
||||
c = b"abc"
|
||||
# Temporarily redirect stdout
|
||||
old_stdout = sys.stdout
|
||||
sys.stdout = mystdout = StringIO()
|
||||
mystdout = StringIO()
|
||||
monkeypatch.setattr(sys, "stdout", mystdout)
|
||||
|
||||
# Act
|
||||
IptcImagePlugin.dump(c)
|
||||
|
||||
# Reset stdout
|
||||
sys.stdout = old_stdout
|
||||
with pytest.warns(DeprecationWarning):
|
||||
IptcImagePlugin.dump(c)
|
||||
|
||||
# Assert
|
||||
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 ._binary import i16be as i16
|
||||
from ._binary import i32be as i32
|
||||
from ._deprecate import deprecate
|
||||
|
||||
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
|
||||
|
||||
|
||||
def _i(c):
|
||||
return i32((b"\0\0\0\0" + c)[-4:])
|
||||
|
||||
|
||||
def _i8(c: int | bytes) -> int:
|
||||
return c if isinstance(c, int) else c[0]
|
||||
|
||||
|
||||
def i(c):
|
||||
return i32((PAD + c)[-4:])
|
||||
deprecate("IptcImagePlugin.i", 12)
|
||||
return _i(c)
|
||||
|
||||
|
||||
def dump(c):
|
||||
deprecate("IptcImagePlugin.dump", 12)
|
||||
for i in c:
|
||||
print("%02x" % _i8(i), end=" ")
|
||||
print()
|
||||
|
@ -56,7 +69,7 @@ class IptcImageFile(ImageFile.ImageFile):
|
|||
format_description = "IPTC/NAA"
|
||||
|
||||
def getint(self, key):
|
||||
return i(self.info[key])
|
||||
return _i(self.info[key])
|
||||
|
||||
def field(self):
|
||||
#
|
||||
|
@ -80,7 +93,7 @@ class IptcImageFile(ImageFile.ImageFile):
|
|||
elif size == 128:
|
||||
size = 0
|
||||
elif size > 128:
|
||||
size = i(self.fp.read(size - 128))
|
||||
size = _i(self.fp.read(size - 128))
|
||||
else:
|
||||
size = i16(s, 3)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user