mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Corrected getxmp() descending into XML
This commit is contained in:
		
							parent
							
								
									20bd9e9261
								
							
						
					
					
						commit
						c1fbe2d975
					
				| 
						 | 
					@ -828,7 +828,16 @@ class TestFileJpeg:
 | 
				
			||||||
            xmp = im.getxmp()
 | 
					            xmp = im.getxmp()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            assert isinstance(xmp, dict)
 | 
					            assert isinstance(xmp, dict)
 | 
				
			||||||
            assert xmp["Description"]["Version"] == "10.4"
 | 
					
 | 
				
			||||||
 | 
					            description = xmp["xmpmeta"]["RDF"]["Description"]
 | 
				
			||||||
 | 
					            assert description["DerivedFrom"] is None
 | 
				
			||||||
 | 
					            assert (
 | 
				
			||||||
 | 
					                description["Look"]["Description"]["Group"]["Alt"]["li"] == "Profiles"
 | 
				
			||||||
 | 
					            )
 | 
				
			||||||
 | 
					            assert description["ToneCurve"]["Seq"]["li"] == ["0, 0", "255, 255"]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            # Attribute
 | 
				
			||||||
 | 
					            assert description["Version"] == "10.4"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@pytest.mark.skipif(not is_win32(), reason="Windows only")
 | 
					@pytest.mark.skipif(not is_win32(), reason="Windows only")
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -492,12 +492,29 @@ class JpegImageFile(ImageFile.ImageFile):
 | 
				
			||||||
            if segment == "APP1":
 | 
					            if segment == "APP1":
 | 
				
			||||||
                marker, xmp_tags = content.rsplit(b"\x00", 1)
 | 
					                marker, xmp_tags = content.rsplit(b"\x00", 1)
 | 
				
			||||||
                if marker == b"http://ns.adobe.com/xap/1.0/":
 | 
					                if marker == b"http://ns.adobe.com/xap/1.0/":
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    def get_name(tag):
 | 
				
			||||||
 | 
					                        return tag.split("}")[1]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    def get_value(element):
 | 
				
			||||||
 | 
					                        children = list(element)
 | 
				
			||||||
 | 
					                        if children:
 | 
				
			||||||
 | 
					                            value = {get_name(k): v for k, v in element.attrib.items()}
 | 
				
			||||||
 | 
					                            for child in children:
 | 
				
			||||||
 | 
					                                name = get_name(child.tag)
 | 
				
			||||||
 | 
					                                child_value = get_value(child)
 | 
				
			||||||
 | 
					                                if name in value:
 | 
				
			||||||
 | 
					                                    if not isinstance(value[name], list):
 | 
				
			||||||
 | 
					                                        value[name] = [value[name]]
 | 
				
			||||||
 | 
					                                    value[name].append(child_value)
 | 
				
			||||||
 | 
					                                else:
 | 
				
			||||||
 | 
					                                    value[name] = child_value
 | 
				
			||||||
 | 
					                            return value
 | 
				
			||||||
 | 
					                        else:
 | 
				
			||||||
 | 
					                            return element.text
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    root = xml.etree.ElementTree.fromstring(xmp_tags)
 | 
					                    root = xml.etree.ElementTree.fromstring(xmp_tags)
 | 
				
			||||||
                    for element in root.findall(".//"):
 | 
					                    self._xmp[get_name(root.tag)] = get_value(root)
 | 
				
			||||||
                        self._xmp[element.tag.split("}")[1]] = {
 | 
					 | 
				
			||||||
                            child.split("}")[1]: value
 | 
					 | 
				
			||||||
                            for child, value in element.attrib.items()
 | 
					 | 
				
			||||||
                        }
 | 
					 | 
				
			||||||
        return self._xmp
 | 
					        return self._xmp
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user