Skip to content

Commit

Permalink
Recovering parser is needed for files where strings like (OCA#910)
Browse files Browse the repository at this point in the history
xmlns:ds="http://www.w3.org/2000/09/xmldsig#""
are present: even if lxml raises
{XMLSyntaxError}xmlns:ds: 'http://www.w3.org/2000/09/xmldsig#"' is not a valid URI
such files are accepted by SDI
  • Loading branch information
eLBati authored Feb 5, 2019
1 parent f4617cd commit 6f4ed24
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions l10n_it_fatturapa/models/ir_attachment.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,23 @@ def decrypt_to_xml(self, signed_file, xml_file):
return xml_file

def remove_xades_sign(self, xml):
root = ET.XML(xml)
# Recovering parser is needed for files where strings like
# xmlns:ds="http://www.w3.org/2000/09/xmldsig#""
# are present: even if lxml raises
# {XMLSyntaxError}xmlns:ds:
# 'http://www.w3.org/2000/09/xmldsig#"' is not a valid URI
# such files are accepted by SDI
recovering_parser = ET.XMLParser(recover=True)
root = ET.XML(xml, parser=recovering_parser)
for elem in root.iter('*'):
if elem.tag.find('Signature') > -1:
elem.getparent().remove(elem)
break
return ET.tostring(root)

def strip_xml_content(self, xml):
root = ET.XML(xml)
recovering_parser = ET.XMLParser(recover=True)
root = ET.XML(xml, parser=recovering_parser)
for elem in root.iter('*'):
if elem.text is not None:
elem.text = elem.text.strip()
Expand Down Expand Up @@ -168,7 +176,8 @@ def get_fattura_elettronica_preview(self):
xslt = ET.parse(xsl_path)
xml_string = self.get_xml_string()
xml_file = BytesIO(xml_string)
dom = ET.parse(xml_file)
recovering_parser = ET.XMLParser(recover=True)
dom = ET.parse(xml_file, parser=recovering_parser)
transform = ET.XSLT(xslt)
newdom = transform(dom)
return ET.tostring(newdom, pretty_print=True)

0 comments on commit 6f4ed24

Please sign in to comment.