facho/facho.py: adiciona replacement_for para sustitucion.
FossilOrigin-Name: 5e9210afdf4577388a206310ded9abbcf129d02f3818671aba3aad1282726466
This commit is contained in:
@@ -82,6 +82,9 @@ class LXMLBuilder:
|
||||
def append(self, elem, child):
|
||||
elem.append(child)
|
||||
|
||||
def remove(self, elem):
|
||||
elem.getparent().remove(elem)
|
||||
|
||||
def set_text(self, elem, text):
|
||||
elem.text = text
|
||||
|
||||
@@ -164,6 +167,11 @@ class FachoXML:
|
||||
def placeholder_for(self, xpath):
|
||||
return self.find_or_create_element(xpath)
|
||||
|
||||
def replacement_for(self, xpath, new_xpath, content, **attrs):
|
||||
elem = self.get_element(xpath)
|
||||
self.builder.remove(elem)
|
||||
return self.set_element(new_xpath, content, **attrs)
|
||||
|
||||
def find_or_create_element(self, xpath, append=False):
|
||||
"""
|
||||
@param xpath ruta xpath para crear o consultar de un solo elemendo
|
||||
|
||||
Reference in New Issue
Block a user