def __find_matches(pattern_pieces, directory):
    import glob

    result = []
    if not _os.path.isdir(directory):
        return []

    piece = pattern_pieces[0]
    last = len(pattern_pieces) == 1
    if piece == '**':
        if not last:
            remaining_pieces = pattern_pieces[1:]

        for root, dirs, files in _os.walk(directory):
            if last:
                # At the end of a pattern, "**" just recursively matches
                # directories.
                result += [root]
            else:
                # Recurse downward, trying to match the rest of the
                # pattern.
                sub_result = __find_matches(remaining_pieces, root)
                for partial_path in sub_result:
                    result += [partial_path]

    else:
        # Regular glob pattern.

        matches = glob.glob(_os.path.join(directory, piece))
        if len(matches) > 0:
            if last:
                for match in matches:
                    result += [match]
            else:
                remaining_pieces = pattern_pieces[1:]
                for match in matches:
                    sub_result = __find_matches(remaining_pieces, match)
                    for partial_path in sub_result:
                        result += [partial_path]

    # Normalize the paths.

    for i in range(len(result)):
        result[i] = _os.path.normpath(result[i])

    return result
Test if sending to a gc'd callback works gracefully.
dataset/ETHPy150Open AppScale/appscale/AppServer/lib/grizzled/grizzled/file/__init__.py/__find_matches--crossover with--dataset/ETHPy150Open enthought/mayavi/tvtk/tests/test_messenger.py/TestMessenger.test_send_on_dead_ref