<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def escape(msg):
 """Takes a raw IRC message and returns a girc-escaped message."""

    msg = msg.replace(escape_character, 'girc-escaped-character')
    for escape_key, irc_char in format_dict.items():
        msg = msg.replace(irc_char, escape_character + escape_key)

    # convert colour codes
    new_msg = ''
    while len(msg):
        if msg.startswith(escape_character + 'c'):
            new_msg += msg[:2]
            msg = msg[2:]

            if not len(msg):
                new_msg += '[]'
                continue

            colours, msg = extract_irc_colours(msg)
            new_msg += colours
        else:
            new_msg += msg[0]
            msg = msg[1:]

    new_msg = new_msg.replace('girc-escaped-character', escape_character + escape_character)
    return new_msg