import re


def patternize(pattern, flags=re.IGNORECASE, attr='fullmatch'):
    """
    Converts `pattern` to a function that accepts a single argument and returns True if the argument matches.

    :param pattern: Pattern to convert.  Either a string (which will be converted to a regex), a regex, or a callable.
    :param flags: Flags used when compiling regular expressions.  Only used if `pattern` is a `str`
    :param attr: Name of the method on a compiled regex that actually does matching.  'match', 'fullmatch', 'search',
    'findall` and `finditer` might be good choices.
    :return: a callable.


    pattern can be:
    - a compiled regular expression, which will be tested using pattern.fullmatch(...) (or another attr if specified.)
    - a string, which will be compiled into a regular expression and then tested using the above.
    - a callable, which returns True (or something evaluating as True) if the result succeeds.

    The result of whatever pattern returns is stored in event.result
    """
    if not callable(pattern):
        if isinstance(pattern, str):
            pattern = re.compile(pattern, flags)
        pattern = getattr(pattern, attr)
    return pattern