import fnmatch


def find_file(contents, pattern):
    """
    Find the file matching the given filename pattern.

    Searches the dictionary of Debian package archive entries reported by
    :func:`deb_pkg_tools.package.inspect_package()`.

    :param contents: The dictionary of package archive entries.
    :param pattern: The filename pattern to match (:mod:`fnmatch` syntax).
    :returns: The metadata of the matched file.
    :raises: :exc:`exceptions.AssertionError` if zero or more than one
             archive entry is found.
    """
    matches = []
    for filename, metadata in contents.items():
        if fnmatch.fnmatch(filename, pattern):
            matches.append(metadata)
    assert len(matches) == 1, "Expected to match exactly one archive entry!"
    return matches[0]