do not accept int in PIL._binary.i8

This commit is contained in:
Nulano 2023-12-29 23:18:08 +01:00
parent 6a33d6d170
commit 3396ce102d
2 changed files with 11 additions and 8 deletions

View File

@ -20,26 +20,29 @@ import os
import tempfile import tempfile
from . import Image, ImageFile from . import Image, ImageFile
from ._binary import i8, o8
from ._binary import i16be as i16 from ._binary import i16be as i16
from ._binary import i32be as i32 from ._binary import i32be as i32
COMPRESSION = {1: "raw", 5: "jpeg"} COMPRESSION = {1: "raw", 5: "jpeg"}
PAD = o8(0) * 4 PAD = b"\0\0\0\0"
# #
# Helpers # Helpers
def _i8(c: int | bytes) -> int:
return c if isinstance(c, int) else c[0]
def i(c): def i(c):
return i32((PAD + c)[-4:]) return i32((PAD + c)[-4:])
def dump(c): def dump(c):
for i in c: for i in c:
print("%02x" % i8(i), end=" ") print("%02x" % _i8(i), end=" ")
print() print()
@ -103,10 +106,10 @@ class IptcImageFile(ImageFile.ImageFile):
self.info[tag] = tagdata self.info[tag] = tagdata
# mode # mode
layers = i8(self.info[(3, 60)][0]) layers = self.info[(3, 60)][0]
component = i8(self.info[(3, 60)][1]) component = self.info[(3, 60)][1]
if (3, 65) in self.info: if (3, 65) in self.info:
id = i8(self.info[(3, 65)][0]) - 1 id = self.info[(3, 65)][0] - 1
else: else:
id = 0 id = 0
if layers == 1 and not component: if layers == 1 and not component:

View File

@ -18,8 +18,8 @@ from __future__ import annotations
from struct import pack, unpack_from from struct import pack, unpack_from
def i8(c: int | bytes) -> int: def i8(c: bytes) -> int:
return c if c.__class__ is int else c[0] # type: ignore[index, return-value] return c[0]
def o8(i: int) -> bytes: def o8(i: int) -> bytes: