def fnmatch_ex(pattern, path):
path = PurePath(path)<EOL>iswin32 = sys.platform.startswith("<STR_LIT>")<EOL>if iswin32 and sep not in pattern and posix_sep in pattern:<EOL><INDENT>pattern = pattern.replace(posix_sep, sep)<EOL><DEDENT>if sep not in pattern:<EOL><INDENT>name = path.name<EOL><DEDENT>else:<EOL><INDENT>name = six.text_type(path)<EOL><DEDENT>return fnmatch.fnmatch(name, pattern)<EOL>
FNMatcher port from py.path.common which works with PurePath() instances.

    The difference between this algorithm and PurePath.match() is that the latter matches "**" glob expressions
    for each part of the path, while this algorithm uses the whole path instead.

    For example:
        "tests/foo/bar/doc/test_foo.py" matches pattern "tests/**/doc/test*.py" with this algorithm, but not with
        PurePath.match().

    This algorithm was ported to keep backward-compatibility with existing settings which assume paths match according
    this logic.

    References:
    * https://bugs.python.org/issue29249
    * https://bugs.python.org/issue34731