Gets good old csv data from a file.

    Args:
        file_name: The name of the local file, or the holder for the
            extension type when the file_contents are supplied.
        encoding: Loads the file with the specified cell encoding.
        file_contents: The file-like object holding contents of file_name.
            If left as None, then file_name is directly loaded.
        on_demand: Requests that a yielder be used in place of a full data
            copy.

def get_data_csv(file_name, encoding='utf-8', file_contents=None, on_demand=False):
    '''
    Gets good old csv data from a file.

    Args:
        file_name: The name of the local file, or the holder for the
            extension type when the file_contents are supplied.
        encoding: Loads the file with the specified cell encoding.
        file_contents: The file-like object holding contents of file_name.
            If left as None, then file_name is directly loaded.
        on_demand: Requests that a yielder be used in place of a full data
            copy.
    '''
    def yield_csv(csv_contents, csv_file):
        try:
            for line in csv_contents:
                yield line
        finally:
            try:
                csv_file.close()
            except:
                pass

    def process_csv(csv_contents, csv_file):
        return [line for line in yield_csv(csv_contents, csv_file)]

    if file_contents:
        csv_file = BytesIO(file_contents)
    else:
        # Don't use 'open as' format, as on_demand loads shouldn't close the file early
        csv_file = open(file_name, 'rb')
    reader = csv.reader(csv_file, dialect=csv.excel, encoding=encoding)

    if on_demand:
        table = yield_csv(reader, csv_file)
    else:
        table = process_csv(reader, csv_file)

    return [table]