import gzip


def _get_fh(path, mode='r'):
    """Return a file handle for given path and attempt to uncompress/compress
    files ending in '.gz'"""

    if path.endswith('.gz'):
        fh = gzip.open(path, mode=mode)
    else:
        fh = open(path, mode=mode)
    return fh