import glob


def _single_glob(pattern):
    """Returns the file matching a given pattern. An error is raised if
    no file/multiple files match the pattern

    Parameters
    ----------
    pattern : str
        The pattern to match.

    Returns
    -------
    output : str or None
        The filename if existant.
    """
    filenames = glob.glob(pattern)
    if not filenames:
        raise ValueError('Non exitant file with pattern {0}'.format(pattern))

    if len(filenames) > 1:
        raise ValueError('Non unique file with pattern {0}'.format(pattern))

    return filenames[0]