From 7c0c7bf5c08293f0d5877818a9900d18b9a3bf62 Mon Sep 17 00:00:00 2001 From: r00t Date: Sat, 26 May 2018 09:11:07 -0400 Subject: [PATCH] gorram it lxml. --- bdisk/confparse.py | 10 +--------- bdisk/utils.py | 3 ++- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/bdisk/confparse.py b/bdisk/confparse.py index ec8080f..39874b9 100644 --- a/bdisk/confparse.py +++ b/bdisk/confparse.py @@ -308,19 +308,11 @@ class Conf(object): def validate(self): # TODO: perform further validations that we can't do in XSD. - # TODO: FIX ME. ALWAYS RETURNS INVALID: - # lxml.etree.DocumentInvalid: Element 'bdisk': No matching global declaration available for the validation root. xsd = self.get_xsd() self.xsd = etree.XMLSchema(xsd) # This would return a bool if it validates or not. #self.xsd.validate(self.xml) # We want to get a more detailed exception. - #xml = self.xml_suppl.return_full().getroottree() - xml = self.xml_suppl.return_full() - with open('/tmp/bdisk.xml', 'wb') as f: - f.write(etree.tostring(xml)) - with open('/tmp/bdisk.xsd', 'wb') as f: - f.write(etree.tostring(xsd)) + xml = etree.fromstring(self.xml_suppl.return_full()) self.xsd.assertValid(xml) - #print(self.xsd.validate(xml)) return() diff --git a/bdisk/utils.py b/bdisk/utils.py index a057f1b..63045da 100644 --- a/bdisk/utils.py +++ b/bdisk/utils.py @@ -977,13 +977,14 @@ class xml_supplicant(object): def return_full(self): #nsmap = self.return_naked_ns() + # https://stackoverflow.com/a/22553145/733214 local_xml = lxml.etree.Element('bdisk', nsmap = self.orig_xml.nsmap, attrib = self.orig_xml.attrib) local_xml.text = '\n ' for elem in self.xml.xpath('/bdisk/profile'): local_xml.append(copy.deepcopy(elem)) - return(local_xml) + return(lxml.etree.tostring(local_xml)) def return_naked_ns(self): # It's so stupid I have to do this.