'Rewrites given entry url. Raises UrlRewritingError if failed.'

@plugin.priority(255)
def url_rewrite(self, task, entry):

    tries = 0
    while (self.url_rewritable(task, entry) and entry.accepted):
        tries += 1
        if (tries > 20):
            raise UrlRewritingError((u'URL    rewriting    was    left    in    infinite    loop    while    rewriting    url    for    %s,    some    rewriter    is    returning    always    True' % entry))
        for urlrewriter in plugin.get_plugins(interface=u'urlrewriter'):
            name = urlrewriter.name
            if (name in self.disabled_rewriters):
                log.trace(u"Skipping    rewriter    %s    since    it's    disabled", name)
                continue
            try:
                if urlrewriter.instance.url_rewritable(task, entry):
                    old_url = entry[u'url']
                    log.debug((u'Url    rewriting    %s' % entry[u'url']))
                    urlrewriter.instance.url_rewrite(task, entry)
                    if (entry[u'url'] != old_url):
                        if (entry.get(u'urls') and (old_url in entry.get(u'urls'))):
                            entry[u'urls'][entry[u'urls'].index(old_url)] = entry[u'url']
                        log.info(u"Entry    '%s'    URL    rewritten    to    %s    (with    %s)", entry[u'title'], entry[u'url'], name)
            except UrlRewritingError as r:
                raise UrlRewritingError((u'URL    rewriting    %s    failed:    %s' % (name, r.value)))
            except plugin.PluginError as e:
                raise UrlRewritingError((u'URL    rewriting    %s    failed:    %s' % (name, e.value)))
            except Exception as e:
                log.exception(e)
                raise UrlRewritingError((u'%s:    Internal    error    with    url    %s' % (name, entry[u'url'])))
