Replace slice and comparison with endswith

This commit is contained in:
Hugo van Kemenade 2025-02-15 19:38:03 +02:00
parent 1e574e6f8b
commit 9665eb3972
3 changed files with 5 additions and 5 deletions

View File

@ -155,9 +155,9 @@ class ImImageFile(ImageFile.ImageFile):
msg = "not an IM file" msg = "not an IM file"
raise SyntaxError(msg) raise SyntaxError(msg)
if s[-2:] == b"\r\n": if s.endswith(b"\r\n"):
s = s[:-2] s = s[:-2]
elif s[-1:] == b"\n": elif s.endswith(b"\n"):
s = s[:-1] s = s[:-1]
try: try:

View File

@ -54,7 +54,7 @@ class MicImageFile(TiffImagePlugin.TiffImageFile):
self.images = [ self.images = [
path path
for path in self.ole.listdir() for path in self.ole.listdir()
if path[1:] and path[0][-4:] == ".ACI" and path[1] == "Image" if path[1:] and path[0].endswith(".ACI") and path[1] == "Image"
] ]
# if we didn't find any images, this is probably not # if we didn't find any images, this is probably not

View File

@ -67,9 +67,9 @@ class XpmImageFile(ImageFile.ImageFile):
for _ in range(pal): for _ in range(pal):
s = self.fp.readline() s = self.fp.readline()
if s[-2:] == b"\r\n": if s.endswith(b"\r\n"):
s = s[:-2] s = s[:-2]
elif s[-1:] in b"\r\n": elif s.endswith((b"\r", b"\n")):
s = s[:-1] s = s[:-1]
c = s[1] c = s[1]