def translate(pat):
i, n = <NUM_LIT:0>, len(pat)<EOL>res = '<STR_LIT>'<EOL>while i < n:<EOL><INDENT>c = pat[i]<EOL>i = i+<NUM_LIT:1><EOL>if c == '<STR_LIT:*>':<EOL><INDENT>res = res + '<STR_LIT>'<EOL><DEDENT>elif c == '<STR_LIT:?>':<EOL><INDENT>res = res + '<STR_LIT:.>'<EOL><DEDENT>elif c == '<STR_LIT:[>':<EOL><INDENT>j = i<EOL>if j < n and pat[j] == '<STR_LIT:!>':<EOL><INDENT>j = j+<NUM_LIT:1><EOL><DEDENT>if j < n and pat[j] == '<STR_LIT:]>':<EOL><INDENT>j = j+<NUM_LIT:1><EOL><DEDENT>while j < n and pat[j] != '<STR_LIT:]>':<EOL><INDENT>j = j+<NUM_LIT:1><EOL><DEDENT>if j >= n:<EOL><INDENT>res = res + '<STR_LIT>'<EOL><DEDENT>else:<EOL><INDENT>stuff = pat[i:j].replace('<STR_LIT:\\>','<STR_LIT>')<EOL>i = j+<NUM_LIT:1><EOL>if stuff[<NUM_LIT:0>] == '<STR_LIT:!>':<EOL><INDENT>stuff = '<STR_LIT>' + stuff[<NUM_LIT:1>:]<EOL><DEDENT>elif stuff[<NUM_LIT:0>] == '<STR_LIT>':<EOL><INDENT>stuff = '<STR_LIT:\\>' + stuff<EOL><DEDENT>res = '<STR_LIT>' % (res, stuff)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>res = res + re.escape(c)<EOL><DEDENT><DEDENT>return res + '<STR_LIT>'<EOL>
Translate a shell PATTERN to a regular expression.

    There is no way to quote meta-characters.