Skip to content

Commit

Permalink
Merge pull request #8045 from radarhere/strings
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed May 10, 2024
2 parents 0cad346 + a335687 commit bfbe339
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 16 deletions.
4 changes: 1 addition & 3 deletions Tests/test_file_eps.py
Expand Up @@ -336,9 +336,7 @@ def test_readline_psfile(tmp_path: Path) -> None:
strings = ["something", "else", "baz", "bif"]

def _test_readline(t: EpsImagePlugin.PSFile, ending: str) -> None:
ending = "Failure with line ending: %s" % (
"".join("%s" % ord(s) for s in ending)
)
ending = f"Failure with line ending: {''.join(str(ord(s)) for s in ending)}"
assert t.readline().strip("\r\n") == "something", ending
assert t.readline().strip("\r\n") == "else", ending
assert t.readline().strip("\r\n") == "baz", ending
Expand Down
10 changes: 5 additions & 5 deletions Tests/test_image_access.py
Expand Up @@ -409,13 +409,14 @@ def test_embeddable(self) -> None:
from setuptools.command import build_ext

with open("embed_pil.c", "w", encoding="utf-8") as fh:
home = sys.prefix.replace("\\", "\\\\")
fh.write(
"""
f"""
#include "Python.h"
int main(int argc, char* argv[])
{
char *home = "%s";
{{
char *home = "{home}";
wchar_t *whome = Py_DecodeLocale(home, NULL);
Py_SetPythonHome(whome);
Expand All @@ -430,9 +431,8 @@ def test_embeddable(self) -> None:
PyMem_RawFree(whome);
return 0;
}
}}
"""
% sys.prefix.replace("\\", "\\\\")
)

compiler = getattr(build_ext, "new_compiler")()
Expand Down
4 changes: 2 additions & 2 deletions selftest.py
Expand Up @@ -165,9 +165,9 @@ def testimage() -> None:
print("Running selftest:")
status = doctest.testmod(sys.modules[__name__])
if status[0]:
print("*** %s tests of %d failed." % status)
print(f"*** {status[0]} tests of {status[1]} failed.")
exit_status = 1
else:
print("--- %s tests passed." % status[1])
print(f"--- {status[1]} tests passed.")

sys.exit(exit_status)
2 changes: 1 addition & 1 deletion src/PIL/IptcImagePlugin.py
Expand Up @@ -57,7 +57,7 @@ def dump(c: Sequence[int | bytes]) -> None:
""".. deprecated:: 10.2.0"""
deprecate("IptcImagePlugin.dump", 12)
for i in c:
print("%02x" % _i8(i), end=" ")
print(f"{_i8(i):02x}", end=" ")
print()


Expand Down
9 changes: 4 additions & 5 deletions src/PIL/PdfParser.py
Expand Up @@ -823,11 +823,10 @@ def get_value(cls, data, offset, expect_indirect=None, max_nesting=-1):
m = cls.re_stream_start.match(data, offset)
if m:
try:
stream_len = int(result[b"Length"])
except (TypeError, KeyError, ValueError) as e:
msg = "bad or missing Length in stream dict (%r)" % result.get(
b"Length", None
)
stream_len_str = result.get(b"Length")
stream_len = int(stream_len_str)
except (TypeError, ValueError) as e:
msg = f"bad or missing Length in stream dict ({stream_len_str})"
raise PdfFormatError(msg) from e
stream_data = data[m.end() : m.end() + stream_len]
m = cls.re_stream_end.match(data, m.end() + stream_len)
Expand Down

0 comments on commit bfbe339

Please sign in to comment.