def _ical_escape(text):
    """
    Format value according to iCalendar TEXT escaping rules.
    from https://github.com/collective/icalendar/blob/4.0.2/src/icalendar/parser.py#L20
    """
    return (
        text.replace(r'\N', '\n')
        .replace('\\', '\\\\')
        .replace(';', r'\;')
        .replace(',', r'\,')
        .replace('\r\n', r'\n')
        .replace('\n', r'\n')
    )