'Process and rewrite image URIs.'

def process_doc(self, app, doctree):

    docname = app.env.docname
    for node in doctree.traverse(nodes.image):
        candidates = {}
        node['candidates'] = candidates
        imguri = node['uri']
        if imguri.startswith('data:'):
            candidates['?'] = imguri
            continue
        elif (imguri.find('://') != (-1)):
            candidates['?'] = imguri
            continue
        (rel_imgpath, full_imgpath) = app.env.relfn2path(imguri, docname)
        if app.config.language:
            i18n_full_imgpath = search_image_for_language(full_imgpath, app.env)
            if (i18n_full_imgpath != full_imgpath):
                full_imgpath = i18n_full_imgpath
                rel_imgpath = relative_path(path.join(app.srcdir, 'dummy'), i18n_full_imgpath)
        node['uri'] = rel_imgpath
        if rel_imgpath.endswith((os.extsep + '*')):
            if app.config.language:
                i18n_imguri = get_image_filename_for_language(imguri, app.env)
                (_, full_i18n_imgpath) = app.env.relfn2path(i18n_imguri, docname)
                self.collect_candidates(app.env, full_i18n_imgpath, candidates, node)
            self.collect_candidates(app.env, full_imgpath, candidates, node)
        else:
            candidates['*'] = rel_imgpath
        for imgpath in itervalues(candidates):
            app.env.dependencies[docname].add(imgpath)
            if (not os.access(path.join(app.srcdir, imgpath), os.R_OK)):
                logger.warning(('image    file    not    readable:    %s' % imgpath), location=node, type='image', subtype='not_readable')
                continue
            app.env.images.add_file(docname, imgpath)
