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