parameters: (filename, location, flatten=True)
docstring: 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.
function: def unzip_file(filename, location, flatten=True):
  
      # type: (str, str, bool) -> None
  
      """
  
      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.
  
      """
  
      ensure_dir(location)
  
      zipfp = open(filename, 'rb')
  
      try:
  
          zip = zipfile.ZipFile(zipfp, allowZip64=True)
  
          leading = has_leading_dir(zip.namelist()) and flatten
  
          for info in zip.infolist():
  
              name = info.filename
  
              fn = name
  
              if leading:
  
                  fn = split_leading_dir(name)[1]
  
              fn = os.path.join(location, fn)
  
              dir = os.path.dirname(fn)
  
              if not is_within_directory(location, fn):
  
                  message = (
  
                      'The zip file ({}) has a file ({}) trying to install '
  
                      'outside target directory ({})'
  
                  )
  
                  raise InstallationError(message.format(filename, fn, location))
  
              if fn.endswith('/') or fn.endswith('\\'):
  
                  # A directory
  
                  ensure_dir(fn)
  
              else:
  
                  ensure_dir(dir)
  
                  # Don't use read() to avoid allocating an arbitrarily large
  
                  # chunk of memory for the file's content
  
                  fp = zip.open(name)
  
                  try:
  
                      with open(fn, 'wb') as destfp:
  
                          shutil.copyfileobj(fp, destfp)
  
                  finally:
  
                      fp.close()
  
                      if zip_item_is_executable(info):
  
                          set_extracted_file_to_default_mode_plus_executable(fn)
  
      finally:
  
          zipfp.close()
function_tokens: def unzip_file ( filename , location , flatten = True ) : # type: (str, str, bool) -> None ensure_dir ( location ) zipfp = open ( filename , 'rb' ) try : zip = zipfile . ZipFile ( zipfp , allowZip64 = True ) leading = has_leading_dir ( zip . namelist ( ) ) and flatten for info in zip . infolist ( ) : name = info . filename fn = name if leading : fn = split_leading_dir ( name ) [ 1 ] fn = os . path . join ( location , fn ) dir = os . path . dirname ( fn ) if not is_within_directory ( location , fn ) : message = ( 'The zip file ({}) has a file ({}) trying to install ' 'outside target directory ({})' ) raise InstallationError ( message . format ( filename , fn , location ) ) if fn . endswith ( '/' ) or fn . endswith ( '\\' ) : # A directory ensure_dir ( fn ) else : ensure_dir ( dir ) # Don't use read() to avoid allocating an arbitrarily large # chunk of memory for the file's content fp = zip . open ( name ) try : with open ( fn , 'wb' ) as destfp : shutil . copyfileobj ( fp , destfp ) finally : fp . close ( ) if zip_item_is_executable ( info ) : set_extracted_file_to_default_mode_plus_executable ( fn ) finally : zipfp . close ( )