<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def handle_link(self, link, py3o_base, closing_link):
 """transform a py3o link into a proper Genshi statement rebase a py3o link at a proper place in the tree to be ready for Genshi replacement """

        # OLD open office version
        if link.text is not None and link.text.strip():
            if not link.text == py3o_base:
                msg = "url and text do not match in '%s'" % link.text
                raise TemplateException(msg)

        # new open office version
        elif len(link):
            if not link[0].text == py3o_base:
                msg = "url and text do not match in '%s'" % link.text
                raise TemplateException(msg)
        else:
            raise TemplateException("Link text not found")

        # find out if the instruction is inside a table
        parent = link.getparent()
        keep_start_boundary = False
        keep_end_boundary = False

        if parent.getparent() is not None and parent.getparent().tag == (
            "{%s}table-cell" % self.namespaces['table']
        ):
            # we are in a table
            opening_paragraph = parent
            opening_cell = opening_paragraph.getparent()

            # same for closing
            closing_paragraph = closing_link.getparent()
            closing_cell = closing_paragraph.getparent()

            if opening_cell == closing_cell:
                # block is fully in a single cell
                opening_row = opening_paragraph
                closing_row = closing_paragraph
            else:
                opening_row = opening_cell.getparent()
                closing_row = closing_cell.getparent()

        elif parent.tag == "{%s}p" % self.namespaces['text']:
            # if we are using text we want to keep start/end nodes
            keep_start_boundary, keep_end_boundary = detect_keep_boundary(
                link, closing_link, self.namespaces
            )
            # we are in a text paragraph
            opening_row = parent
            closing_row = closing_link.getparent()

        else:
            raise NotImplementedError(
                "We handle urls in tables or text paragraph only"
            )

        # max split is one
        instruction, instruction_value = py3o_base.split("=", 1)
        instruction_value = instruction_value.strip('"')

        attribs = dict()
        attribs['{%s}strip' % GENSHI_URI] = 'True'
        attribs['{%s}%s' % (GENSHI_URI, instruction)] = instruction_value

        genshi_node = lxml.etree.Element(
            'span',
            attrib=attribs,
            nsmap={'py': GENSHI_URI},
        )

        link.getparent().remove(link)
        closing_link.getparent().remove(closing_link)

        try:
            move_siblings(
                opening_row, closing_row, genshi_node,
                keep_start_boundary=keep_start_boundary,
                keep_end_boundary=keep_end_boundary,
            )
        except ValueError as e:
            log.exception(e)
            raise TemplateException("Could not move siblings for '%s'" %
                                    py3o_base)