import pathlib
import gzip


def _get_opener(filename: str):
    """Helper to get the opener type based upon the filename."""
    path = pathlib.Path(filename)
    if not path.is_file():
        raise OSError(f'Filename "{filename}" does not exist.')
    extension = path.suffix
    if extension == '.gz':
        opener = gzip.open
    else:
        opener = open
    return opener