Skip to content

Commit 9665eb3

Browse files
committed
Replace slice and comparison with endswith
1 parent 1e574e6 commit 9665eb3

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/PIL/ImImagePlugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ def _open(self) -> None:
155155
msg = "not an IM file"
156156
raise SyntaxError(msg)
157157

158-
if s[-2:] == b"\r\n":
158+
if s.endswith(b"\r\n"):
159159
s = s[:-2]
160-
elif s[-1:] == b"\n":
160+
elif s.endswith(b"\n"):
161161
s = s[:-1]
162162

163163
try:

src/PIL/MicImagePlugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def _open(self) -> None:
5454
self.images = [
5555
path
5656
for path in self.ole.listdir()
57-
if path[1:] and path[0][-4:] == ".ACI" and path[1] == "Image"
57+
if path[1:] and path[0].endswith(".ACI") and path[1] == "Image"
5858
]
5959

6060
# if we didn't find any images, this is probably not

src/PIL/XpmImagePlugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ def _open(self) -> None:
6767

6868
for _ in range(pal):
6969
s = self.fp.readline()
70-
if s[-2:] == b"\r\n":
70+
if s.endswith(b"\r\n"):
7171
s = s[:-2]
72-
elif s[-1:] in b"\r\n":
72+
elif s.endswith((b"\r", b"\n")):
7373
s = s[:-1]
7474

7575
c = s[1]

0 commit comments

Comments
 (0)