import io
import bz2


def open_bzip_file(filename, mode, **kwargs):
    """Open a bzip file.
    """
    if 't' in mode:
        return io.TextIOWrapper(bz2.BZ2File(filename, mode[0]))
    else:
        return bz2.BZ2File(filename, mode)