<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def concatenate_and_rewrite(self, paths, output_filename, variant=None):
 """Concatenate together files and rewrite urls"""

        stylesheets = []
        for path in paths:
            def reconstruct(match):
                quote = match.group(1) or ''
                asset_path = match.group(2)
                if NON_REWRITABLE_URL.match(asset_path):
                    return "url(%s%s%s)" % (quote, asset_path, quote)
                asset_url = self.construct_asset_path(asset_path, path,
                                                      output_filename, variant)
                return "url(%s)" % asset_url
            content = self.read_text(path)
            # content needs to be unicode to avoid explosions with non-ascii chars
            content = re.sub(URL_DETECTOR, reconstruct, content)
            stylesheets.append(content)
        return '\n'.join(stylesheets)