XML entities to be stored as ElementTree objects, not as "Elements". #82
This commit is contained in:
parent
f106852e11
commit
769dc23cdc
1 changed files with 9 additions and 13 deletions
|
|
@ -1608,7 +1608,7 @@ class XMLBox(Jp2kBox):
|
||||||
offset of the box from the start of the file.
|
offset of the box from the start of the file.
|
||||||
longname : str
|
longname : str
|
||||||
more verbose description of the box.
|
more verbose description of the box.
|
||||||
xml : ElementTree.Element
|
xml : ElementTree object
|
||||||
XML section.
|
XML section.
|
||||||
"""
|
"""
|
||||||
def __init__(self, xml=None, filename=None, length=0, offset=-1):
|
def __init__(self, xml=None, filename=None, length=0, offset=-1):
|
||||||
|
|
@ -1636,10 +1636,7 @@ class XMLBox(Jp2kBox):
|
||||||
msg = Jp2kBox.__str__(self)
|
msg = Jp2kBox.__str__(self)
|
||||||
xml = self.xml
|
xml = self.xml
|
||||||
if self.xml is not None:
|
if self.xml is not None:
|
||||||
try:
|
msg += _pretty_print_xml(self.xml)
|
||||||
msg += _pretty_print_xml(self.xml)
|
|
||||||
except TypeError:
|
|
||||||
msg += _pretty_print_xml(self.xml.getroot())
|
|
||||||
else:
|
else:
|
||||||
msg += '\n {0}'.format(xml)
|
msg += '\n {0}'.format(xml)
|
||||||
return msg
|
return msg
|
||||||
|
|
@ -1682,7 +1679,8 @@ class XMLBox(Jp2kBox):
|
||||||
text = text.rstrip('\0')
|
text = text.rstrip('\0')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
xml = ET.fromstring(text)
|
elt = ET.fromstring(text)
|
||||||
|
xml = ET.ElementTree(elt)
|
||||||
except ParseError as parse_error:
|
except ParseError as parse_error:
|
||||||
msg = 'A problem was encountered while parsing an XML box: "{0}"'
|
msg = 'A problem was encountered while parsing an XML box: "{0}"'
|
||||||
msg = msg.format(str(parse_error))
|
msg = msg.format(str(parse_error))
|
||||||
|
|
@ -1926,13 +1924,11 @@ class UUIDBox(Jp2kBox):
|
||||||
# XMP data. Parse as XML. Seems to be a difference between
|
# XMP data. Parse as XML. Seems to be a difference between
|
||||||
# ElementTree in version 2.7 and 3.3.
|
# ElementTree in version 2.7 and 3.3.
|
||||||
if sys.hexversion < 0x03000000:
|
if sys.hexversion < 0x03000000:
|
||||||
#parser = ET.XMLParser(encoding='utf-8')
|
elt = ET.fromstring(raw_data)
|
||||||
#import pdb; pdb.set_trace()
|
|
||||||
#self.data = ET.fromstringlist(raw_data, parser=parser)
|
|
||||||
self.data = ET.fromstring(raw_data)
|
|
||||||
else:
|
else:
|
||||||
text = raw_data.decode('utf-8')
|
text = raw_data.decode('utf-8')
|
||||||
self.data = ET.fromstring(text)
|
elt = ET.fromstring(text)
|
||||||
|
self.data = ET.ElementTree(elt)
|
||||||
elif the_uuid.bytes == b'JpgTiffExif->JP2':
|
elif the_uuid.bytes == b'JpgTiffExif->JP2':
|
||||||
exif_obj = Exif(raw_data)
|
exif_obj = Exif(raw_data)
|
||||||
ifds = OrderedDict()
|
ifds = OrderedDict()
|
||||||
|
|
@ -2555,8 +2551,8 @@ def _pretty_print_xml(xml, level=0):
|
||||||
"""Pretty print XML data.
|
"""Pretty print XML data.
|
||||||
"""
|
"""
|
||||||
xml = copy.deepcopy(xml)
|
xml = copy.deepcopy(xml)
|
||||||
_indent(xml, level=level)
|
_indent(xml.getroot(), level=level)
|
||||||
xmltext = ET.tostring(xml).decode('utf-8')
|
xmltext = ET.tostring(xml.getroot()).decode('utf-8')
|
||||||
|
|
||||||
# Indent it a bit.
|
# Indent it a bit.
|
||||||
lst = [(' ' + x) for x in xmltext.split('\n')]
|
lst = [(' ' + x) for x in xmltext.split('\n')]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue