'Replace all links in name using replace_func, which must be a
callable that accepts a URL and returns the replaced URL. It must also
have a \'replaced\' attribute that is set to True if any actual
replacement is done. Convenient ways of creating such callables are
using the :class:`LinkReplacer` and :class:`LinkRebaser` classes.'

def replace_links(self, name, replace_func):

    media_type = self.mime_map.get(name, guess_type(name))
    if (name == self.opf_name):
        for elem in self.opf_xpath(u'//*[@href]'):
            elem.set(u'href', replace_func(elem.get(u'href')))
    elif (media_type.lower() in OEB_DOCS):
        rewrite_links(self.parsed(name), replace_func)
    elif (media_type.lower() in OEB_STYLES):
        replaceUrls(self.parsed(name), replace_func)
    elif (media_type.lower() == guess_type(u'toc.ncx')):
        for elem in self.parsed(name).xpath(u'//*[@src]'):
            elem.set(u'src', replace_func(elem.get(u'src')))
    if replace_func.replaced:
        self.dirty(name)
    return replace_func.replaced
