From 17c48db318a7e48d16909f08973df94b27dcc736 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 30 Dec 2020 22:35:54 +1100 Subject: [PATCH 1/5] Use context manager --- Tests/test_image_getxmp.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Tests/test_image_getxmp.py b/Tests/test_image_getxmp.py index 91c6634f1..2ca7f0fde 100644 --- a/Tests/test_image_getxmp.py +++ b/Tests/test_image_getxmp.py @@ -2,8 +2,8 @@ from PIL import Image def test_getxmp(): - im = Image.open("Tests/images/xmp_test.jpg") - type_repr = repr(type(im.getxmp())) + with Image.open("Tests/images/xmp_test.jpg") as im: + type_repr = repr(type(im.getxmp())) - assert "dict" in type_repr - assert isinstance(im.getxmp()["Description"][0]["Version"], str) + assert "dict" in type_repr + assert isinstance(im.getxmp()["Description"][0]["Version"], str) From 06b7b97a7aa771761d746e5a6fe424b543baa231 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 30 Dec 2020 22:39:49 +1100 Subject: [PATCH 2/5] Use isinstance to check type --- Tests/test_image_getxmp.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Tests/test_image_getxmp.py b/Tests/test_image_getxmp.py index 2ca7f0fde..33c531931 100644 --- a/Tests/test_image_getxmp.py +++ b/Tests/test_image_getxmp.py @@ -3,7 +3,8 @@ from PIL import Image def test_getxmp(): with Image.open("Tests/images/xmp_test.jpg") as im: - type_repr = repr(type(im.getxmp())) + xmp = im.getxmp() + + assert isinstance(xmp, dict) + assert isinstance(xmp["Description"][0]["Version"], str) - assert "dict" in type_repr - assert isinstance(im.getxmp()["Description"][0]["Version"], str) From 8c8b11003554255028ecc48939e61d3547618b9d Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 30 Dec 2020 22:40:39 +1100 Subject: [PATCH 3/5] Check string value --- Tests/test_image_getxmp.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Tests/test_image_getxmp.py b/Tests/test_image_getxmp.py index 33c531931..19df631d5 100644 --- a/Tests/test_image_getxmp.py +++ b/Tests/test_image_getxmp.py @@ -6,5 +6,4 @@ def test_getxmp(): xmp = im.getxmp() assert isinstance(xmp, dict) - assert isinstance(xmp["Description"][0]["Version"], str) - + assert xmp["Description"][0]["Version"] == "10.4" From ad9614be7a1b9fa5c9a43f99def78e56d3ca8ed7 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 30 Dec 2020 22:46:49 +1100 Subject: [PATCH 4/5] Renamed variable --- src/PIL/Image.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 63468df99..4a94385c6 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1334,10 +1334,10 @@ class Image: if marker == b"http://ns.adobe.com/xap/1.0/": root = xml.etree.ElementTree.fromstring(xmp_tags) for element in root.findall(".//"): - xmp_atribs = [] + xmp_attribs = [] for child, value in element.attrib.items(): - xmp_atribs.append({child.split("}")[1]: value}) - self._xmp.update({element.tag.split("}")[1]: xmp_atribs}) + xmp_attribs.append({child.split("}")[1]: value}) + self._xmp.update({element.tag.split("}")[1]: xmp_attribs}) return self._xmp def getim(self): From 3c482b1b0b286aa5bc54c6a4547d92abe7b87e75 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Wed, 30 Dec 2020 23:10:29 +1100 Subject: [PATCH 5/5] Changed list of single item dictionaries to dictionary --- Tests/test_image_getxmp.py | 2 +- src/PIL/Image.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Tests/test_image_getxmp.py b/Tests/test_image_getxmp.py index 19df631d5..a684d6f0c 100644 --- a/Tests/test_image_getxmp.py +++ b/Tests/test_image_getxmp.py @@ -6,4 +6,4 @@ def test_getxmp(): xmp = im.getxmp() assert isinstance(xmp, dict) - assert xmp["Description"][0]["Version"] == "10.4" + assert xmp["Description"]["Version"] == "10.4" diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 4a94385c6..df78fb809 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -1334,10 +1334,10 @@ class Image: if marker == b"http://ns.adobe.com/xap/1.0/": root = xml.etree.ElementTree.fromstring(xmp_tags) for element in root.findall(".//"): - xmp_attribs = [] - for child, value in element.attrib.items(): - xmp_attribs.append({child.split("}")[1]: value}) - self._xmp.update({element.tag.split("}")[1]: xmp_attribs}) + self._xmp[element.tag.split("}")[1]] = { + child.split("}")[1]: value + for child, value in element.attrib.items() + } return self._xmp def getim(self):