def _open_table(tbl_filename, encoding):
    """
    Transparently open the compressed or text table file.

    Can be used as a context manager in a 'with' statement.
    """
    path = _table_filename(tbl_filename)
    if path.endswith('.gz'):
        # gzip.open() cannot use mode='rt' until Python2.7 support
        # is gone; until then use TextIOWrapper
        gzfile = GzipFile(path, mode='r')
        gzfile.read1 = gzfile.read  # Python2 hack
        with TextIOWrapper(gzfile, encoding=encoding) as f:
            yield f
    else:
        with io.open(path, encoding=encoding) as f:
            yield f
Transparently open the compressed or text table file.

    Can be used as a context manager in a 'with' statement.