def multiline_escape(string):
    if EMBEDDED_NEWLINE_MATCHER.search(string):
        lines = string.split('\n')
        return (
            '""\n'
            + '\n'.join('"{}\\n"'.format(escape(line)) for line in lines[:-1])
            + ('\n"{}"'.format(escape(lines[-1])) if len(lines[-1]) else ""))
    else:
        return '"{}"'.format(escape(string))