Skip to content

Commit

Permalink
Merge pull request #5380 from radarhere/accept
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Apr 3, 2021
2 parents ee079ae + 60da129 commit e2ac1d1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
8 changes: 4 additions & 4 deletions Tests/test_file_dds.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,25 +136,25 @@ def test_uncompressed_rgb():
)


def test__validate_true():
def test__accept_true():
"""Check valid prefix"""
# Arrange
prefix = b"DDS etc"

# Act
output = DdsImagePlugin._validate(prefix)
output = DdsImagePlugin._accept(prefix)

# Assert
assert output


def test__validate_false():
def test__accept_false():
"""Check invalid prefix"""
# Arrange
prefix = b"something invalid"

# Act
output = DdsImagePlugin._validate(prefix)
output = DdsImagePlugin._accept(prefix)

# Assert
assert not output
Expand Down
8 changes: 5 additions & 3 deletions src/PIL/BlpImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,9 +417,11 @@ def _load(self):
self.set_as_raw(bytes(data))


Image.register_open(
BlpImageFile.format, BlpImageFile, lambda p: p[:4] in (b"BLP1", b"BLP2")
)
def _accept(prefix):
return prefix[:4] in (b"BLP1", b"BLP2")


Image.register_open(BlpImageFile.format, BlpImageFile, _accept)
Image.register_extension(BlpImageFile.format, ".blp")

Image.register_decoder("BLP1", BLP1Decoder)
Expand Down
4 changes: 2 additions & 2 deletions src/PIL/DdsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ def load_seek(self, pos):
pass


def _validate(prefix):
def _accept(prefix):
return prefix[:4] == b"DDS "


Image.register_open(DdsImageFile.format, DdsImageFile, _validate)
Image.register_open(DdsImageFile.format, DdsImageFile, _accept)
Image.register_extension(DdsImageFile.format, ".dds")
4 changes: 2 additions & 2 deletions src/PIL/FtexImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ def load_seek(self, pos):
pass


def _validate(prefix):
def _accept(prefix):
return prefix[:4] == MAGIC


Image.register_open(FtexImageFile.format, FtexImageFile, _validate)
Image.register_open(FtexImageFile.format, FtexImageFile, _accept)
Image.register_extensions(FtexImageFile.format, [".ftc", ".ftu"])
6 changes: 5 additions & 1 deletion src/PIL/IcnsImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,11 @@ def _save(im, fp, filename):
fp.write(f.read())


Image.register_open(IcnsImageFile.format, IcnsImageFile, lambda x: x[:4] == b"icns")
def _accept(prefix):
return prefix[:4] == b"icns"


Image.register_open(IcnsImageFile.format, IcnsImageFile, _accept)
Image.register_extension(IcnsImageFile.format, ".icns")

if sys.platform == "darwin":
Expand Down

0 comments on commit e2ac1d1

Please sign in to comment.