def try_match(request_origin, maybe_regex):
if isinstance(maybe_regex, RegexObject):<EOL><INDENT>return re.match(maybe_regex, request_origin)<EOL><DEDENT>elif probably_regex(maybe_regex):<EOL><INDENT>return re.match(maybe_regex, request_origin, flags=re.IGNORECASE)<EOL><DEDENT>else:<EOL><INDENT>try:<EOL><INDENT>return request_origin.lower() == maybe_regex.lower()<EOL><DEDENT>except AttributeError:<EOL><INDENT>return request_origin == maybe_regex<EOL><DEDENT><DEDENT>
Safely attempts to match a pattern or string to a request origin.