def match(self, environ):
verb = environ['<STR_LIT>'].upper()<EOL>path = environ['<STR_LIT>'] or '<STR_LIT:/>'<EOL>if verb == '<STR_LIT>':<EOL><INDENT>methods = ['<STR_LIT>', verb, '<STR_LIT:GET>', '<STR_LIT>']<EOL><DEDENT>else:<EOL><INDENT>methods = ['<STR_LIT>', verb, '<STR_LIT>']<EOL><DEDENT>for method in methods:<EOL><INDENT>if method in self.static and path in self.static[method]:<EOL><INDENT>target, getargs = self.static[method][path]<EOL>return target, getargs(path) if getargs else {}<EOL><DEDENT>elif method in self.dyna_regexes:<EOL><INDENT>for combined, rules in self.dyna_regexes[method]:<EOL><INDENT>match = combined(path)<EOL>if match:<EOL><INDENT>target, getargs = rules[match.lastindex - <NUM_LIT:1>]<EOL>return target, getargs(path) if getargs else {}<EOL><DEDENT><DEDENT><DEDENT><DEDENT>allowed = set([])<EOL>nocheck = set(methods)<EOL>for method in set(self.static) - nocheck:<EOL><INDENT>if path in self.static[method]:<EOL><INDENT>allowed.add(verb)<EOL><DEDENT><DEDENT>for method in set(self.dyna_regexes) - allowed - nocheck:<EOL><INDENT>for combined, rules in self.dyna_regexes[method]:<EOL><INDENT>match = combined(path)<EOL>if match:<EOL><INDENT>allowed.add(method)<EOL><DEDENT><DEDENT><DEDENT>if allowed:<EOL><INDENT>allow_header = "<STR_LIT:U+002C>".join(sorted(allowed))<EOL>raise HTTPError(<NUM_LIT>, "<STR_LIT>", Allow=allow_header)<EOL><DEDENT>raise HTTPError(<NUM_LIT>, "<STR_LIT>" + repr(path))<EOL>
Return a (target, url_args) tuple or raise HTTPError(400/404/405).