def importer_for_filepath(filepath, extensions_map, importer_kwargs=None):
    r"""
    Given a filepath, return the appropriate importer as mapped by the
    extension map.

    Parameters
    ----------
    filepath : `pathlib.Path`
        The filepath to get importers for
    extensions_map : dictionary (String, :class:`menpo.io.base.Importer`)
        A map from extensions to importers. The importers are expected to be
        a subclass of :class:`Importer`. The extensions are expected to
        contain the leading period eg. `.obj`.
    importer_kwargs: dictionary, optional
        kwargs that will be supplied to the importer if not None.

    Returns
    --------
    importer: :class:`menpo.io.base.Importer` instance
        Importer as found in the `extensions_map` instantiated for the
        filepath provided.

    """
    suffix = ''.join(filepath.suffixes)
    if suffix.isupper():
        # If for some reason the ending is in capital letters, make them lower
        # case first.
        suffix = suffix.lower()
    importer_type = extensions_map.get(suffix)
    # we couldn't find an importer for all the suffixes (e.g .foo.bar)
    # maybe the file stem has '.' in it? -> try again but this time just use the
    # final suffix (.bar). (Note we first try '.foo.bar' as we want to catch
    # cases like 'pkl.gz')
    if importer_type is None and len(filepath.suffixes) > 1:
        suffix = filepath.suffix
        importer_type = extensions_map.get(suffix)
    if importer_type is None:
        raise ValueError("{} does not have a "
                         "suitable importer.".format(suffix))
    if importer_kwargs is not None:
        return importer_type(str(filepath), **importer_kwargs)
    else:
        return importer_type(str(filepath))
dataset/ETHPy150Open menpo/menpo/menpo/io/input/base.py/importer_for_filepath/original