Skip to content

Commit

Permalink
Merge pull request #6816 from radarhere/warning
Browse files Browse the repository at this point in the history
Fixed BytesWarnings
  • Loading branch information
hugovk committed Dec 21, 2022
2 parents 7b6f4c6 + 9670343 commit 2f3561f
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/PIL/PpmImagePlugin.py
Expand Up @@ -208,7 +208,9 @@ def _decode_bitonal(self):
tokens = b"".join(block.split())
for token in tokens:
if token not in (48, 49):
raise ValueError(f"Invalid token for this mode: {bytes([token])}")
raise ValueError(
b"Invalid token for this mode: %s" % bytes([token])
)
data = (data + tokens)[:total_bytes]
invert = bytes.maketrans(b"01", b"\xFF\x00")
return data.translate(invert)
Expand Down Expand Up @@ -242,13 +244,13 @@ def _decode_blocks(self, maxval):
half_token = tokens.pop() # save half token for later
if len(half_token) > max_len: # prevent buildup of half_token
raise ValueError(
f"Token too long found in data: {half_token[:max_len + 1]}"
b"Token too long found in data: %s" % half_token[: max_len + 1]
)

for token in tokens:
if len(token) > max_len:
raise ValueError(
f"Token too long found in data: {token[:max_len + 1]}"
b"Token too long found in data: %s" % token[: max_len + 1]
)
value = int(token)
if value > maxval:
Expand Down

0 comments on commit 2f3561f

Please sign in to comment.