Do not require curly bracket in tag name

This commit is contained in:
Andrew Murray 2023-07-10 22:05:28 +10:00
parent 2488167f33
commit 3f78ba80f9
3 changed files with 9 additions and 1 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 788 B

View File

@ -898,6 +898,14 @@ class TestFileJpeg:
with Image.open("Tests/images/hopper.jpg") as im: with Image.open("Tests/images/hopper.jpg") as im:
assert im.getxmp() == {} 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):
assert im.getxmp() == {}
else:
assert im.getxmp() == {"xmpmeta": {"key": "value"}}
def test_getxmp_padded(self): def test_getxmp_padded(self):
with Image.open("Tests/images/xmp_padded.jpg") as im: with Image.open("Tests/images/xmp_padded.jpg") as im:
if ElementTree is None: if ElementTree is None:

View File

@ -1380,7 +1380,7 @@ class Image:
def _getxmp(self, xmp_tags): def _getxmp(self, xmp_tags):
def get_name(tag): def get_name(tag):
return tag.split("}")[1] return re.sub("^{[^}]+}", "", tag)
def get_value(element): def get_value(element):
value = {get_name(k): v for k, v in element.attrib.items()} value = {get_name(k): v for k, v in element.attrib.items()}