# Path: mfr/extensions/tabular/exceptions.py
# class TableTooBigError(TabularRendererError):
# 
#     __TYPE = 'tabular_table_too_big'
# 
#     def __init__(self, message, *args, code: int=400, nbr_cols: int=0, nbr_rows: int=0, **kwargs):
#         super().__init__(message, *args, code=code, **kwargs)
#         self.nbr_cols = nbr_cols
#         self.nbr_rows = nbr_rows
#         self.attr_stack.append([self.__TYPE, {
#             'nbr_cols': self.nbr_cols,
#             'nbr_rows': self.nbr_rows
#         }])
# 
# Path: mfr/extensions/tabular/utilities.py
# def header_population(headers):
#     """make column headers from a list
#     :param headers: list of column headers
#     :return: a list of dictionaries
#     """
#     return [{'id': field, 'name': field, 'field': field, 'sortable': True} for field in headers]


import xlrd
from collections import OrderedDict
from ..exceptions import TableTooBigError
from ..utilities import header_population
from mfr.extensions.tabular.compat import range, basestring



def xlsx_xlrd(fp):
    """Read and convert a xlsx file to JSON format using the xlrd library
    :param fp: File pointer object
    :return: tuple of table headers and data
    """
    max_size = 10000

    wb = xlrd.open_workbook(fp.name)

    sheets = OrderedDict()

    for sheet in wb.sheets():
        if sheet.ncols > max_size or sheet.nrows > max_size:

# Path: mfr/extensions/tabular/exceptions.py
# class TableTooBigError(TabularRendererError):
# 
#     __TYPE = 'tabular_table_too_big'
# 
#     def __init__(self, message, *args, code: int=400, nbr_cols: int=0, nbr_rows: int=0, **kwargs):
#         super().__init__(message, *args, code=code, **kwargs)
#         self.nbr_cols = nbr_cols
#         self.nbr_rows = nbr_rows
#         self.attr_stack.append([self.__TYPE, {
#             'nbr_cols': self.nbr_cols,
#             'nbr_rows': self.nbr_rows
#         }])
# 
# Path: mfr/extensions/tabular/utilities.py
# def header_population(headers):
#     """make column headers from a list
#     :param headers: list of column headers
#     :return: a list of dictionaries
#     """
#     return [{'id': field, 'name': field, 'field': field, 'sortable': True} for field in headers]


# Path: mfr/extensions/tabular/libs/xlrd_tools.py
import xlrd
from collections import OrderedDict
from ..exceptions import TableTooBigError
from ..utilities import header_population
from mfr.extensions.tabular.compat import range, basestring




def xlsx_xlrd(fp):
    """Read and convert a xlsx file to JSON format using the xlrd library
    :param fp: File pointer object
    :return: tuple of table headers and data
    """
    max_size = 10000

    wb = xlrd.open_workbook(fp.name)

    sheets = OrderedDict()

    for sheet in wb.sheets():
        if sheet.ncols > max_size or sheet.nrows > max_size:

            raise TableTooBigError('Table is too large to render.', '.xlsx',