def escape(msg):
msg = msg.replace(escape_character, '<STR_LIT>')<EOL>for escape_key, irc_char in format_dict.items():<EOL><INDENT>msg = msg.replace(irc_char, escape_character + escape_key)<EOL><DEDENT>new_msg = '<STR_LIT>'<EOL>while len(msg):<EOL><INDENT>if msg.startswith(escape_character + '<STR_LIT:c>'):<EOL><INDENT>new_msg += msg[:<NUM_LIT:2>]<EOL>msg = msg[<NUM_LIT:2>:]<EOL>if not len(msg):<EOL><INDENT>new_msg += '<STR_LIT>'<EOL>continue<EOL><DEDENT>colours, msg = extract_irc_colours(msg)<EOL>new_msg += colours<EOL><DEDENT>else:<EOL><INDENT>new_msg += msg[<NUM_LIT:0>]<EOL>msg = msg[<NUM_LIT:1>:]<EOL><DEDENT><DEDENT>new_msg = new_msg.replace('<STR_LIT>', escape_character + escape_character)<EOL>return new_msg<EOL>
Takes a raw IRC message and returns a girc-escaped message.