Merge pull request #8045 from radarhere/strings

This commit is contained in:
Hugo van Kemenade 2024-05-10 18:44:37 +03:00 committed by GitHub
commit bfbe339ae3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 13 additions and 16 deletions

View File

@ -336,9 +336,7 @@ def test_readline_psfile(tmp_path: Path) -> None:
strings = ["something", "else", "baz", "bif"] strings = ["something", "else", "baz", "bif"]
def _test_readline(t: EpsImagePlugin.PSFile, ending: str) -> None: def _test_readline(t: EpsImagePlugin.PSFile, ending: str) -> None:
ending = "Failure with line ending: %s" % ( ending = f"Failure with line ending: {''.join(str(ord(s)) for s in ending)}"
"".join("%s" % ord(s) for s in ending)
)
assert t.readline().strip("\r\n") == "something", ending assert t.readline().strip("\r\n") == "something", ending
assert t.readline().strip("\r\n") == "else", ending assert t.readline().strip("\r\n") == "else", ending
assert t.readline().strip("\r\n") == "baz", ending assert t.readline().strip("\r\n") == "baz", ending

View File

@ -409,13 +409,14 @@ class TestEmbeddable:
from setuptools.command import build_ext from setuptools.command import build_ext
with open("embed_pil.c", "w", encoding="utf-8") as fh: with open("embed_pil.c", "w", encoding="utf-8") as fh:
home = sys.prefix.replace("\\", "\\\\")
fh.write( fh.write(
""" f"""
#include "Python.h" #include "Python.h"
int main(int argc, char* argv[]) int main(int argc, char* argv[])
{ {{
char *home = "%s"; char *home = "{home}";
wchar_t *whome = Py_DecodeLocale(home, NULL); wchar_t *whome = Py_DecodeLocale(home, NULL);
Py_SetPythonHome(whome); Py_SetPythonHome(whome);
@ -430,9 +431,8 @@ int main(int argc, char* argv[])
PyMem_RawFree(whome); PyMem_RawFree(whome);
return 0; return 0;
} }}
""" """
% sys.prefix.replace("\\", "\\\\")
) )
compiler = getattr(build_ext, "new_compiler")() compiler = getattr(build_ext, "new_compiler")()

View File

@ -165,9 +165,9 @@ if __name__ == "__main__":
print("Running selftest:") print("Running selftest:")
status = doctest.testmod(sys.modules[__name__]) status = doctest.testmod(sys.modules[__name__])
if status[0]: if status[0]:
print("*** %s tests of %d failed." % status) print(f"*** {status[0]} tests of {status[1]} failed.")
exit_status = 1 exit_status = 1
else: else:
print("--- %s tests passed." % status[1]) print(f"--- {status[1]} tests passed.")
sys.exit(exit_status) sys.exit(exit_status)

View File

@ -57,7 +57,7 @@ def dump(c: Sequence[int | bytes]) -> None:
""".. deprecated:: 10.2.0""" """.. deprecated:: 10.2.0"""
deprecate("IptcImagePlugin.dump", 12) deprecate("IptcImagePlugin.dump", 12)
for i in c: for i in c:
print("%02x" % _i8(i), end=" ") print(f"{_i8(i):02x}", end=" ")
print() print()

View File

@ -823,11 +823,10 @@ class PdfParser:
m = cls.re_stream_start.match(data, offset) m = cls.re_stream_start.match(data, offset)
if m: if m:
try: try:
stream_len = int(result[b"Length"]) stream_len_str = result.get(b"Length")
except (TypeError, KeyError, ValueError) as e: stream_len = int(stream_len_str)
msg = "bad or missing Length in stream dict (%r)" % result.get( except (TypeError, ValueError) as e:
b"Length", None msg = f"bad or missing Length in stream dict ({stream_len_str})"
)
raise PdfFormatError(msg) from e raise PdfFormatError(msg) from e
stream_data = data[m.end() : m.end() + stream_len] stream_data = data[m.end() : m.end() + stream_len]
m = cls.re_stream_end.match(data, m.end() + stream_len) m = cls.re_stream_end.match(data, m.end() + stream_len)