def csv_encode(text):
    """Format text for CSV."""

    encode_table = {
        '"': '""',
        '\n': '',
        '\r': ''
    }

    return '"%s"' % ''.join(
        encode_table.get(c, c) for c in text
    )