def open_file(filename, mode='<STR_LIT:rb>'):
if (('<STR_LIT:r>' not in mode or hasattr(filename, '<STR_LIT>')) and<EOL>(('<STR_LIT:a>' not in mode and '<STR_LIT:w>' not in mode) or hasattr(filename, '<STR_LIT>')) and<EOL>hasattr(filename, '<STR_LIT>')):<EOL><INDENT>return filename<EOL><DEDENT>elif isinstance(filename, string_type):<EOL><INDENT>if filename == '<STR_LIT:->' and '<STR_LIT:r>' in mode:<EOL><INDENT>if PY3:<EOL><INDENT>return sys.stdin.buffer<EOL><DEDENT>return sys.stdin<EOL><DEDENT>elif filename == '<STR_LIT:->' and ('<STR_LIT:w>' in mode or '<STR_LIT:a>' in mode):<EOL><INDENT>if PY3:<EOL><INDENT>return sys.stdout.buffer<EOL><DEDENT>return sys.stdout<EOL><DEDENT>if filename.lower().count('<STR_LIT>'):<EOL><INDENT>assert '<STR_LIT:r>' in mode<EOL>assert filename.count('<STR_LIT::>') == <NUM_LIT:1><EOL>import zipfile<EOL>zipped_file = zipfile.ZipFile(filename.split('<STR_LIT::>')[<NUM_LIT:0>])<EOL>unzipped_file = zipped_file.open(filename.split('<STR_LIT::>')[<NUM_LIT:1>], '<STR_LIT:r>')<EOL>zipped_file.close()<EOL>return unzipped_file<EOL><DEDENT>elif filename.lower().endswith('<STR_LIT>'):<EOL><INDENT>import gzip<EOL>return gzip.open(filename, mode)<EOL><DEDENT>elif filename.lower().endswith('<STR_LIT>'):<EOL><INDENT>import lzma<EOL>tmp = lzma.LZMAFile(filename, mode)<EOL>dir(tmp)<EOL>return tmp<EOL><DEDENT>else:<EOL><INDENT>return open(filename, mode)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>raise Exception('<STR_LIT>')<EOL><DEDENT>
Opens a file for access with the given mode.  This function
transparently wraps gzip and xz files as well as normal files.
You can also open zip files using syntax like:

f = utils.open_file('../semcor-parsed.zip:semcor000.txt')