def open_compressed(filename, mode="<STR_LIT:r>", encoding=None):
<EOL>binary_mode = "<STR_LIT:b>" in mode<EOL>extension = str(filename).split("<STR_LIT:.>")[-<NUM_LIT:1>].lower()<EOL>if binary_mode and encoding:<EOL><INDENT>raise ValueError("<STR_LIT>")<EOL><DEDENT>if extension == "<STR_LIT>":<EOL><INDENT>if lzma is None:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>fobj = lzma.open(filename, mode=mode)<EOL>if binary_mode:<EOL><INDENT>return fobj<EOL><DEDENT>else:<EOL><INDENT>return io.TextIOWrapper(fobj, encoding=encoding)<EOL><DEDENT><DEDENT>elif extension == "<STR_LIT>":<EOL><INDENT>fobj = gzip.GzipFile(filename, mode=mode)<EOL>if binary_mode:<EOL><INDENT>return fobj<EOL><DEDENT>else:<EOL><INDENT>return io.TextIOWrapper(fobj, encoding=encoding)<EOL><DEDENT><DEDENT>elif extension == "<STR_LIT>":<EOL><INDENT>if bz2 is None:<EOL><INDENT>raise RuntimeError("<STR_LIT>")<EOL><DEDENT>if binary_mode:  <EOL><INDENT>return bz2.open(filename, mode=mode)<EOL><DEDENT>else:<EOL><INDENT>if "<STR_LIT:t>" not in mode:<EOL><INDENT>mode += "<STR_LIT:t>"<EOL><DEDENT>return bz2.open(filename, mode=mode, encoding=encoding)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if binary_mode:<EOL><INDENT>return open(filename, mode=mode)<EOL><DEDENT>else:<EOL><INDENT>return open(filename, mode=mode, encoding=encoding)<EOL><DEDENT><DEDENT>
Return a text-based file object from a filename, even if compressed