<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def rewrite_url(self, url, is_image_src=False):
 """ This method is called to rewrite URLs. It uses either ``self.link_rewrite`` or ``self.img_src_rewrite`` depending on the value of ``is_image_src``. The URL is returned unchanged if the corresponding attribute is :obj:`None`. """

        rewrite = self.img_src_rewrite if is_image_src else self.link_rewrite
        if rewrite:
            return rewrite.format(url=urlquote(url))
        return url