def _validate_archive(filename):
 is_file_like = hasattr(filename, 'read')
 if ((not is_file_like) and os.path.isfile(filename)):
  file_format = os.path.splitext(filename)[(-1)]
  if (file_format not in SUPPORTED_FORMATS):
   if (file_format == '.xls'):
    msg = 'openpyxl does not support the old .xls file format, please use xlrd to read this file, or convert it to the more recent .xlsx file format.'
   elif (file_format == '.xlsb'):
    msg = 'openpyxl does not support binary format .xlsb, please convert this file to .xlsx format if you want to open it with openpyxl'
   else:
    msg = ('openpyxl does not support %s file format, please check you can open it with Excel first. Supported formats are: %s' % (file_format, ','.join(SUPPORTED_FORMATS)))
   raise InvalidFileException(msg)
 if is_file_like:
  if (getattr(filename, 'encoding', None) is not None):
   raise IOError('File-object must be opened in binary mode')
 try:
  archive = ZipFile(filename, 'r', ZIP_DEFLATED)
 except BadZipfile:
  f = repair_central_directory(filename, is_file_like)
  archive = ZipFile(f, 'r', ZIP_DEFLATED)
 return archive

def _validate_archive ( filename ) : is_file_like = hasattr ( filename , 'read' ) if ( ( not is_file_like ) and os . path . isfile ( filename ) ) : file_format = os . path . splitext ( filename ) [ ( - 1 ) ] if ( file_format not in SUPPORTED_FORMATS ) : if ( file_format == '.xls' ) : msg = 'openpyxl does not support the old .xls file format, please use xlrd to read this file, or convert it to the more recent .xlsx file format.' elif ( file_format == '.xlsb' ) : msg = 'openpyxl does not support binary format .xlsb, please convert this file to .xlsx format if you want to open it with openpyxl' else : msg = ( 'openpyxl does not support %s file format, please check you can open it with Excel first. Supported formats are: %s' % ( file_format , ',' . join ( SUPPORTED_FORMATS ) ) ) raise InvalidFileException ( msg ) if is_file_like : if ( getattr ( filename , 'encoding' , None ) is not None ) : raise IOError ( 'File-object must be opened in binary mode' ) try : archive = ZipFile ( filename , 'r' , ZIP_DEFLATED ) except BadZipfile : f = repair_central_directory ( filename , is_file_like ) archive = ZipFile ( f , 'r' , ZIP_DEFLATED ) return archive
check the file is a valid zipfile .