src/dirbs/importer/importer_utils.py
def extract_csv_from_zip(filename):
    """Function to extract the csv file contained within the zip file."""
    try:
        with zipfile.ZipFile(filename, 'r') as zf:
            contents = zf.namelist()
            if len(contents) != 1:
                raise zipfile.BadZipFile('There is more than 1 file in the .zip archive.')

            zipfile_basename, zipfile_ext = splitext(basename(filename))
            contents_filename = basename(contents[0])
            contents_basename, contents_ext = splitext(contents_filename)

            if zipfile_basename != contents_basename:
                raise zipfile.BadZipFile('Wrong file name in archive {0} - the filename should match the .zip '
                                         'filename with a different file extension.'.format(filename))

            return zf.open(contents[0], mode='r')

    except zipfile.BadZipFile as e:
        raise zipfile.BadZipFile('Input file is not a valid .zip file: {0}'.format(str(e)))
Function to extract the csv file contained within the zip file.
Function to extract the csv file contained within the zip file.
Function to extract the csv file contained within the zip file .
def extract_csv_from_zip(filename):
    try:
        with zipfile.ZipFile(filename, 'r') as zf:
            contents = zf.namelist()
            if len(contents) != 1:
                raise zipfile.BadZipFile('There is more than 1 file in the .zip archive.')
            zipfile_basename, zipfile_ext = splitext(basename(filename))
            contents_filename = basename(contents[0])
            contents_basename, contents_ext = splitext(contents_filename)
            if zipfile_basename != contents_basename:
                raise zipfile.BadZipFile('Wrong file name in archive {0} - the filename should match the .zip '
                                         'filename with a different file extension.'.format(filename))
            return zf.open(contents[0], mode='r')
    except zipfile.BadZipFile as e:
        raise zipfile.BadZipFile('Input file is not a valid .zip file: {0}'.format(str(e)))
def extract_csv_from_zip ( filename ) : try : with zipfile . ZipFile ( filename , 'r' ) as zf : contents = zf . namelist ( ) if len ( contents ) != 1 : raise zipfile . BadZipFile ( 'There is more than 1 file in the .zip archive.' ) zipfile_basename , zipfile_ext = splitext ( basename ( filename ) ) contents_filename = basename ( contents [ 0 ] ) contents_basename , contents_ext = splitext ( contents_filename ) if zipfile_basename != contents_basename : raise zipfile . BadZipFile ( 'Wrong file name in archive {0} - the filename should match the .zip ' 'filename with a different file extension.' . format ( filename ) ) return zf . open ( contents [ 0 ] , mode = 'r' ) except zipfile . BadZipFile as e : raise zipfile . BadZipFile ( 'Input file is not a valid .zip file: {0}' . format ( str ( e ) ) )
Function to extract the csv file contained within the zip file.
Function to extract the csv file contained within the zip file .
"""Function to extract the csv file contained within the zip file."""
filename