@contextmanager<EOL>def decompress_file(path, compression):
if compression is None:<EOL><INDENT>f = open(path, '<STR_LIT:rb>')<EOL><DEDENT>elif compression == '<STR_LIT>':<EOL><INDENT>f = gzip.open(path, '<STR_LIT:rb>')<EOL><DEDENT>elif compression == '<STR_LIT>':<EOL><INDENT>f = bz2.BZ2File(path, '<STR_LIT:rb>')<EOL><DEDENT>elif compression == '<STR_LIT>':<EOL><INDENT>f = lzma.LZMAFile(path, '<STR_LIT:rb>')<EOL><DEDENT>elif compression == '<STR_LIT>':<EOL><INDENT>zip_file = zipfile.ZipFile(path)<EOL>zip_names = zip_file.namelist()<EOL>if len(zip_names) == <NUM_LIT:1>:<EOL><INDENT>f = zip_file.open(zip_names.pop())<EOL><DEDENT>else:<EOL><INDENT>raise ValueError('<STR_LIT>'<EOL>.format(path))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>msg = '<STR_LIT>'.format(compression)<EOL>raise ValueError(msg)<EOL><DEDENT>try:<EOL><INDENT>yield f<EOL><DEDENT>finally:<EOL><INDENT>f.close()<EOL>if compression == "<STR_LIT>":<EOL><INDENT>zip_file.close()<EOL><DEDENT><DEDENT>
Open a compressed file and return a file object

Parameters
----------
path : str
    The path where the file is read from

compression : {'gzip', 'bz2', 'zip', 'xz', None}
    Name of the decompression to use

Returns
-------
f : file object