mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-01-13 18:56:17 +03:00
Merge pull request #7274 from radarhere/jpeg_xmp
This commit is contained in:
commit
8280fba356
BIN
Tests/images/xmp_no_prefix.jpg
Normal file
BIN
Tests/images/xmp_no_prefix.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 788 B |
BIN
Tests/images/xmp_padded.jpg
Normal file
BIN
Tests/images/xmp_padded.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 778 B |
|
@ -882,7 +882,10 @@ class TestFileJpeg:
|
|||
def test_getxmp(self):
|
||||
with Image.open("Tests/images/xmp_test.jpg") as im:
|
||||
if ElementTree is None:
|
||||
with pytest.warns(UserWarning):
|
||||
with pytest.warns(
|
||||
UserWarning,
|
||||
match="XMP data cannot be read without defusedxml dependency",
|
||||
):
|
||||
assert im.getxmp() == {}
|
||||
else:
|
||||
xmp = im.getxmp()
|
||||
|
@ -905,6 +908,28 @@ class TestFileJpeg:
|
|||
with Image.open("Tests/images/hopper.jpg") as im:
|
||||
assert im.getxmp() == {}
|
||||
|
||||
def test_getxmp_no_prefix(self):
|
||||
with Image.open("Tests/images/xmp_no_prefix.jpg") as im:
|
||||
if ElementTree is None:
|
||||
with pytest.warns(
|
||||
UserWarning,
|
||||
match="XMP data cannot be read without defusedxml dependency",
|
||||
):
|
||||
assert im.getxmp() == {}
|
||||
else:
|
||||
assert im.getxmp() == {"xmpmeta": {"key": "value"}}
|
||||
|
||||
def test_getxmp_padded(self):
|
||||
with Image.open("Tests/images/xmp_padded.jpg") as im:
|
||||
if ElementTree is None:
|
||||
with pytest.warns(
|
||||
UserWarning,
|
||||
match="XMP data cannot be read without defusedxml dependency",
|
||||
):
|
||||
assert im.getxmp() == {}
|
||||
else:
|
||||
assert im.getxmp() == {"xmpmeta": None}
|
||||
|
||||
@pytest.mark.timeout(timeout=1)
|
||||
def test_eof(self):
|
||||
# Even though this decoder never says that it is finished
|
||||
|
|
|
@ -665,7 +665,10 @@ class TestFilePng:
|
|||
def test_getxmp(self):
|
||||
with Image.open("Tests/images/color_snakes.png") as im:
|
||||
if ElementTree is None:
|
||||
with pytest.warns(UserWarning):
|
||||
with pytest.warns(
|
||||
UserWarning,
|
||||
match="XMP data cannot be read without defusedxml dependency",
|
||||
):
|
||||
assert im.getxmp() == {}
|
||||
else:
|
||||
xmp = im.getxmp()
|
||||
|
|
|
@ -734,7 +734,10 @@ class TestFileTiff:
|
|||
def test_getxmp(self):
|
||||
with Image.open("Tests/images/lab.tif") as im:
|
||||
if ElementTree is None:
|
||||
with pytest.warns(UserWarning):
|
||||
with pytest.warns(
|
||||
UserWarning,
|
||||
match="XMP data cannot be read without defusedxml dependency",
|
||||
):
|
||||
assert im.getxmp() == {}
|
||||
else:
|
||||
xmp = im.getxmp()
|
||||
|
|
|
@ -118,7 +118,10 @@ def test_getxmp():
|
|||
|
||||
with Image.open("Tests/images/flower2.webp") as im:
|
||||
if ElementTree is None:
|
||||
with pytest.warns(UserWarning):
|
||||
with pytest.warns(
|
||||
UserWarning,
|
||||
match="XMP data cannot be read without defusedxml dependency",
|
||||
):
|
||||
assert im.getxmp() == {}
|
||||
else:
|
||||
assert (
|
||||
|
|
|
@ -1385,7 +1385,7 @@ class Image:
|
|||
|
||||
def _getxmp(self, xmp_tags):
|
||||
def get_name(tag):
|
||||
return tag.split("}")[1]
|
||||
return re.sub("^{[^}]+}", "", tag)
|
||||
|
||||
def get_value(element):
|
||||
value = {get_name(k): v for k, v in element.attrib.items()}
|
||||
|
|
|
@ -496,7 +496,7 @@ class JpegImageFile(ImageFile.ImageFile):
|
|||
|
||||
for segment, content in self.applist:
|
||||
if segment == "APP1":
|
||||
marker, xmp_tags = content.rsplit(b"\x00", 1)
|
||||
marker, xmp_tags = content.split(b"\x00")[:2]
|
||||
if marker == b"http://ns.adobe.com/xap/1.0/":
|
||||
return self._getxmp(xmp_tags)
|
||||
return {}
|
||||
|
|
Loading…
Reference in New Issue
Block a user