# Path: mfr/extensions/tabular/exceptions.py
# class EmptyTableError(TabularRendererError):
# 
#     __TYPE = 'tabular_empty_table'
# 
#     def __init__(self, message, *args, code: int=400, **kwargs):
#         super().__init__(message, *args, code=code, **kwargs)
#         self.attr_stack.append([self.__TYPE, {}])
# 
# class TabularRendererError(RendererError):
# 
#     def __init__(self, message, *args, **kwargs):
#         super().__init__(message, *args, renderer_class='tabular', **kwargs)
# 
# Path: mfr/extensions/tabular/utilities.py
# def header_population(headers):
# def data_population(in_data, headers=None):
# def strip_comments(src, dest):
# def sav_to_csv(fp):


import re
import csv
from mfr.extensions.tabular.exceptions import EmptyTableError, TabularRendererError
from mfr.extensions.tabular import utilities
    columns = []
    # update the reader field names to avoid duplicate column names when performing row extraction
    for idx, fieldname in enumerate(reader.fieldnames or []):
        column_count = sum(1 for column in columns if fieldname == column['name'])
        if column_count:
            unique_fieldname = '{}-{}'.format(fieldname, column_count + 1)
            reader.fieldnames[idx] = unique_fieldname
        else:
            unique_fieldname = fieldname
        columns.append({
            'id': unique_fieldname,
            'field': unique_fieldname,
            'name': fieldname,
            'sortable': True,
        })

    try:
        rows = [row for row in reader]
    except csv.Error as e:
        if any("field larger than field limit" in errorMsg for errorMsg in e.args):
            raise TabularRendererError(
                'This file contains a field too large to render. '
                'Please download and view it locally.',
                code=400,
                extension='csv',
            ) from e
        else:
            raise TabularRendererError('csv.Error: {}'.format(e), extension='csv') from e

    if not columns and not rows:

# Path: mfr/extensions/tabular/exceptions.py
# class EmptyTableError(TabularRendererError):
# 
#     __TYPE = 'tabular_empty_table'
# 
#     def __init__(self, message, *args, code: int=400, **kwargs):
#         super().__init__(message, *args, code=code, **kwargs)
#         self.attr_stack.append([self.__TYPE, {}])
# 
# class TabularRendererError(RendererError):
# 
#     def __init__(self, message, *args, **kwargs):
#         super().__init__(message, *args, renderer_class='tabular', **kwargs)
# 
# Path: mfr/extensions/tabular/utilities.py
# def header_population(headers):
# def data_population(in_data, headers=None):
# def strip_comments(src, dest):
# def sav_to_csv(fp):


# Path: mfr/extensions/tabular/libs/stdlib_tools.py
import re
import csv
from mfr.extensions.tabular.exceptions import EmptyTableError, TabularRendererError
from mfr.extensions.tabular import utilities

    columns = []
    # update the reader field names to avoid duplicate column names when performing row extraction
    for idx, fieldname in enumerate(reader.fieldnames or []):
        column_count = sum(1 for column in columns if fieldname == column['name'])
        if column_count:
            unique_fieldname = '{}-{}'.format(fieldname, column_count + 1)
            reader.fieldnames[idx] = unique_fieldname
        else:
            unique_fieldname = fieldname
        columns.append({
            'id': unique_fieldname,
            'field': unique_fieldname,
            'name': fieldname,
            'sortable': True,
        })

    try:
        rows = [row for row in reader]
    except csv.Error as e:
        if any("field larger than field limit" in errorMsg for errorMsg in e.args):
            raise TabularRendererError(
                'This file contains a field too large to render. '
                'Please download and view it locally.',
                code=400,
                extension='csv',
            ) from e
        else:
            raise TabularRendererError('csv.Error: {}'.format(e), extension='csv') from e

    if not columns and not rows:

        raise EmptyTableError('Table empty or corrupt.', extension='csv')