Esempio n. 1
0
def replace_notelabel(el: ElementBase, text: str) -> None:
    '修改脚注的标签'
    while el.tag != 'a':
        el = el.getparent()
        if el.tag != 'a':
            a = el.find('.//a')
            if a is not None:
                el = a

    while len(el):
        el = el[0]

    el.text = text
Esempio n. 2
0
def _get_element_at_path(
        current_element: etree.ElementBase, current_path: Sequence[str],
        required_path: Sequence[str], element_maker: ElementMaker
) -> Tuple[etree.ElementBase, Sequence[str]]:
    if required_path != current_path:
        common_path = _get_common_path(current_path, required_path)
        LOGGER.debug('required element path: %s -> %s (common path: %s)',
                     current_path, required_path, common_path)
        for _ in range(len(current_path) - len(common_path)):
            current_element = current_element.getparent()
        current_path = list(common_path)
        for path_fragment in required_path[len(common_path):]:
            try:
                parsed_path_fragment = parse_tag_expression(path_fragment)
                child = parsed_path_fragment.create_node(
                    element_maker=element_maker)
            except ValueError as exc:
                raise ValueError('failed to create node for %r due to %s' %
                                 (path_fragment, exc)) from exc
            current_element.append(child)
            current_element = child
            current_path.append(path_fragment)
    return current_element, current_path
Esempio n. 3
0
 def getparent(self, *args, **kwargs):
     result = ElementBase.getparent(self, *args, **kwargs)
     if result is None:
         return RomElement.window
     else:
         return result
Esempio n. 4
0
 def remove_page_xml_node(cls, nd: etree.ElementBase):
     """
         remove a PageXml element
     """
     nd.getparent().remove(nd)