def unzip_file(filename, location, flatten=True):<EOL>
ensure_dir(location)<EOL>zipfp = open(filename, '<STR_LIT:rb>')<EOL>try:<EOL><INDENT>zip = zipfile.ZipFile(zipfp, allowZip64=True)<EOL>leading = has_leading_dir(zip.namelist()) and flatten<EOL>for info in zip.infolist():<EOL><INDENT>name = info.filename<EOL>fn = name<EOL>if leading:<EOL><INDENT>fn = split_leading_dir(name)[<NUM_LIT:1>]<EOL><DEDENT>fn = os.path.join(location, fn)<EOL>dir = os.path.dirname(fn)<EOL>if fn.endswith('<STR_LIT:/>') or fn.endswith('<STR_LIT:\\>'):<EOL><INDENT>ensure_dir(fn)<EOL><DEDENT>else:<EOL><INDENT>ensure_dir(dir)<EOL>fp = zip.open(name)<EOL>try:<EOL><INDENT>with open(fn, '<STR_LIT:wb>') as destfp:<EOL><INDENT>shutil.copyfileobj(fp, destfp)<EOL><DEDENT><DEDENT>finally:<EOL><INDENT>fp.close()<EOL>mode = info.external_attr >> <NUM_LIT:16><EOL>if mode and stat.S_ISREG(mode) and mode & <NUM_LIT>:<EOL><INDENT>os.chmod(fn, (<NUM_LIT> - current_umask() | <NUM_LIT>))<EOL><DEDENT><DEDENT><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>zipfp.close()<EOL><DEDENT>
Unzip the file (with path `filename`) to the destination `location`.  All
files are written based on system defaults and umask (i.e. permissions are
not preserved), except that regular file members with any execute
permissions (user, group, or world) have "chmod +x" applied after being
written. Note that for windows, any execute changes using os.chmod are
no-ops per the python docs.