improv
FossilOrigin-Name: ea916d6740bcb359fdd6e8685743b2a103e1ef5d36339784e7a4a5717ccf7046
This commit is contained in:
@@ -142,11 +142,16 @@ class FachoXML:
|
||||
elem = self.find_or_create_element('/' + root_tag + xpath)
|
||||
self.builder.append(elem, new_element)
|
||||
|
||||
def fragment(self, xpath, append=False):
|
||||
def fragment(self, xpath, append=False, append_not_exists=False):
|
||||
nodes = xpath.split('/')
|
||||
nodes.pop()
|
||||
root_prefix = '/'.join(nodes)
|
||||
parent = self.find_or_create_element(xpath, append=append)
|
||||
parent = None
|
||||
if append_not_exists:
|
||||
parent = self.get_element(xpath)
|
||||
|
||||
if parent is None:
|
||||
parent = self.find_or_create_element(xpath, append=append)
|
||||
return FachoXML(parent, nsmap=self.nsmap, fragment_prefix=root_prefix)
|
||||
|
||||
def register_alias_xpath(self, alias, xpath):
|
||||
@@ -208,6 +213,10 @@ class FachoXML:
|
||||
self.builder.set_attribute(elem, k, v)
|
||||
return elem
|
||||
|
||||
def get_element(self, xpath):
|
||||
xpath = self.fragment_prefix + self._normalize_xpath(xpath)
|
||||
return self.builder.xpath(self.root, xpath)
|
||||
|
||||
def get_element_text(self, xpath, format_=str):
|
||||
xpath = self.fragment_prefix + self._normalize_xpath(xpath)
|
||||
elem = self.builder.xpath(self.root, xpath)
|
||||
|
||||
@@ -136,12 +136,13 @@ class DianXMLExtensionSoftwareSecurityCode(FachoXMLExtension):
|
||||
self.pin = pin
|
||||
self.invoice_ident = invoice_ident
|
||||
|
||||
def build(self, fachoxml):
|
||||
dian_path = '/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sts:DianExtensions/sts:SoftwareSecurityCode'
|
||||
def build(self, fexml):
|
||||
dian_path = '/fe:Invoice/ext:UBLExtensions/ext:UBLExtension/ext:ExtensionContent/sts:DianExtensions/sts:SoftwareSecurityCode'
|
||||
code = str(self.id_software) + str(self.pin) + str(self.invoice_ident)
|
||||
m = hashlib.sha384()
|
||||
m.update(code.encode('utf-8'))
|
||||
return dian_path, m.hexdigest()
|
||||
fexml.set_element(dian_path, m.hexdigest())
|
||||
return '', []
|
||||
|
||||
|
||||
class DianXMLExtensionSigner(FachoXMLExtension):
|
||||
@@ -226,8 +227,7 @@ class DianXMLExtensionSigner(FachoXMLExtension):
|
||||
#xmlsig take parent root
|
||||
fachoxml.root.remove(signature)
|
||||
|
||||
|
||||
ublextension = fachoxml.fragment('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension', append=True)
|
||||
ublextension = fachoxml.fragment('/fe:Invoice/ext:UBLExtensions/ext:UBLExtension', append_not_exists=True)
|
||||
extcontent = ublextension.find_or_create_element('/ext:UBLExtension:/ext:ExtensionContent')
|
||||
fachoxml.append_element(extcontent, signature)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user