'Iterate over all links in name. If get_line_numbers is True the
yields results of the form (link, line_number, offset). Where
line_number is the line_number at which the link occurs and offset is
the number of characters from the start of the line. Note that offset
could actually encompass several lines if not zero.'

def iterlinks(self, name, get_line_numbers=True):

    media_type = self.mime_map.get(name, guess_type(name))
    if (name == self.opf_name):
        for elem in self.opf_xpath(u'//*[@href]'):
            (yield ((elem.get(u'href'), elem.sourceline, 0) if get_line_numbers else elem.get(u'href')))
    elif (media_type.lower() in OEB_DOCS):
        for (el, attr, link, pos) in iterlinks(self.parsed(name)):
            (yield ((link, el.sourceline, pos) if get_line_numbers else link))
    elif (media_type.lower() in OEB_STYLES):
        if get_line_numbers:
            with self.open(name, u'rb') as f:
                raw = self.decode(f.read()).replace(u'\r\n', u'\n').replace(u'\r', u'\n')
                position = PositionFinder(raw)
                is_in_comment = CommentFinder(raw)
                for (link, offset) in itercsslinks(raw):
                    if (not is_in_comment(offset)):
                        (lnum, col) = position(offset)
                        (yield (link, lnum, col))
        else:
            for link in getUrls(self.parsed(name)):
                (yield link)
    elif (media_type.lower() == guess_type(u'toc.ncx')):
        for elem in self.parsed(name).xpath(u'//*[@src]'):
            (yield ((elem.get(u'src'), elem.sourceline, 0) if get_line_numbers else elem.get(u'src')))
