def escape(pattern):
s = list(pattern)<EOL>alphanum = _alphanum<EOL>for i, c in enumerate(pattern):<EOL><INDENT>if c not in alphanum:<EOL><INDENT>if c == "<STR_LIT>":<EOL><INDENT>s[i] = "<STR_LIT>"<EOL><DEDENT>else:<EOL><INDENT>s[i] = "<STR_LIT:\\>" + c<EOL><DEDENT><DEDENT><DEDENT>return pattern[:<NUM_LIT:0>].join(s)<EOL>
Escape all non-alphanumeric characters in pattern.