def delete_link(self, rel=None, href=lambda _: True):
        """Deletes links from the document.

        Calling code should use this method to remove links instead of
        modyfying ``links`` directly.

        The optional arguments, ``rel`` and ``href`` are used to select the
        links that will be deleted. If neither of the optional arguments are
        given, this method deletes every link in the document. If ``rel`` is
        given, only links for the matching link relationship type are deleted.
        If ``href`` is given, only links with a matching ``href`` are deleted.
        If both ``rel`` and ``href`` are given, only links with matching
        ``href`` for the matching link relationship type are delted.

        Arguments:

        - ``rel``: an optional string specifying the link relationship type of
                   the links to be deleted.
        - ``href``: optionally, a string specifying the ``href`` of the links
                    to be deleted, or a callable that returns true when its
                    single argument is in the set of ``href``s to be deleted.

        """
        if not LINKS_KEY in self.o:
            return

        links = self.o[LINKS_KEY]
        if rel is None:
            for rel in list(links.keys()):
                self.delete_link(rel, href)
            return

        if callable(href):
            href_filter = href
        else:
            href_filter = lambda x: x == href

        links_for_rel = links.setdefault(rel, [])
        if isinstance(links_for_rel, dict):
            links_for_rel = [links_for_rel]

        new_links_for_rel = []
        for link in links_for_rel:
            if not href_filter(link['href']):
                new_links_for_rel.append(link)

        if new_links_for_rel:
            if len(new_links_for_rel) == 1:
                new_links_for_rel = new_links_for_rel[0]

            links[rel] = new_links_for_rel
        else:
            del links[rel]

        if not self.o[LINKS_KEY]:
            del self.o[LINKS_KEY]
Deletes links from the document.

        Calling code should use this method to remove links instead of
        modyfying ``links`` directly.

        The optional arguments, ``rel`` and ``href`` are used to select the
        links that will be deleted. If neither of the optional arguments are
        given, this method deletes every link in the document. If ``rel`` is
        given, only links for the matching link relationship type are deleted.
        If ``href`` is given, only links with a matching ``href`` are deleted.
        If both ``rel`` and ``href`` are given, only links with matching
        ``href`` for the matching link relationship type are delted.

        Arguments:

        - ``rel``: an optional string specifying the link relationship type of
                   the links to be deleted.
        - ``href``: optionally, a string specifying the ``href`` of the links
                    to be deleted, or a callable that returns true when its
                    single argument is in the set of ``href``s to be deleted.