# Path: flattentool/i18n.py
# def _(text):
#     lang = get_language()
#     if lang not in translations:
#         lang = "en"
#     return translations[lang].gettext(text)
# 
# Path: flattentool/input.py
# def path_search(
#     nested_dict, path_list, id_fields=None, path=None, top=False, top_sheet=False
# ):
#     if not path_list:
#         return nested_dict
# 
#     id_fields = id_fields or {}
#     parent_field = path_list[0]
#     path = parent_field if path is None else path + "/" + parent_field
# 
#     if parent_field.endswith("[]") or top:
#         if parent_field.endswith("[]"):
#             parent_field = parent_field[:-2]
#         if parent_field not in nested_dict:
#             nested_dict[parent_field] = TemporaryDict(
#                 keyfield=id_name, top_sheet=top_sheet, xml=xml  # noqa
#             )
#         sub_sheet_id = id_fields.get(path + "/id")
#         if sub_sheet_id not in nested_dict[parent_field]:
#             nested_dict[parent_field][sub_sheet_id] = {}
#         return path_search(
#             nested_dict[parent_field][sub_sheet_id],
#             path_list[1:],
#             id_fields=id_fields,
#             path=path,
#             top_sheet=top_sheet,
#         )
#     else:
#         if parent_field not in nested_dict:
#             nested_dict[parent_field] = OrderedDict()
#         return path_search(
#             nested_dict[parent_field],
#             path_list[1:],
#             id_fields=id_fields,
#             path=path,
#             top_sheet=top_sheet,
#         )
# 
# Path: flattentool/schema.py
# def make_sub_sheet_name(
#     parent_path, property_name, truncation_length=3, path_separator="/"
# ):
#     return (
#         "_".join(
#             x[:truncation_length] for x in parent_path.split(path_separator) if x != "0"
#         )
#         + property_name
#     )[:31]
# 
# Path: flattentool/sheet.py
# class PersistentSheet(Sheet):
#     """
#     A sheet that is persisted in ZODB database.
# 
#     """
# 
#     def __init__(self, columns=None, root_id="", name=None, connection=None):
#         super().__init__(columns=columns, root_id=root_id, name=name)
#         self.connection = connection
#         self.index = 0
#         # Integer key and object value btree.  Store sequential index in order to preserve input order.
#         connection.root.sheet_store[self.name] = BTrees.IOBTree.BTree()
# 
#     @property
#     def lines(self):
#         # btrees iterate in key order.
#         for key, value in self.connection.root.sheet_store[self.name].items():
#             # 5000 chosen by trial and error.  The written row
#             # data is removed from memory as is no loner needed.
#             # All new sheets clear out previous sheets data from memory.
#             if key % 5000 == 0:
#                 self.connection.cacheMinimize()
#             yield value
# 
#     def append_line(self, flattened_dict):
#         self.connection.root.sheet_store[self.name][self.index] = flattened_dict
#         self.index += 1
# 
#     @classmethod
#     def from_sheet(cls, sheet, connection):
#         instance = cls(name=sheet.name, connection=connection)
#         instance.id_columns = copy.deepcopy(sheet.id_columns)
#         instance.columns = copy.deepcopy(sheet.columns)
#         instance.titles = copy.deepcopy(sheet.titles)
#         instance.root_id = sheet.root_id
#         return instance


import codecs
import copy
import os
import tempfile
import uuid
import BTrees.OOBTree
import ijson
import transaction
import xmltodict
import zc.zlibstorage
import ZODB.FileStorage
from collections import OrderedDict
from decimal import Decimal
from warnings import warn
from flattentool.i18n import _
from flattentool.input import path_search
from flattentool.schema import make_sub_sheet_name
from flattentool.sheet import PersistentSheet
                                        _(
                                            'More than one value supplied for "{}". Could not provide rollup, so adding a warning to the relevant cell(s) in the spreadsheet.'
                                        ).format(parent_name + key)
                                    )
                                    flattened_dict[
                                        sheet_key(sheet, parent_name + key + "/0/" + k)
                                    ] = _(
                                        "WARNING: More than one value supplied, consult the relevant sub-sheet for the data."
                                    )
                                elif parent_name + key in self.rollup:
                                    warn(
                                        _(
                                            'More than one value supplied for "{}". Could not provide rollup, so adding a warning to the relevant cell(s) in the spreadsheet.'
                                        ).format(parent_name + key)
                                    )
                                    flattened_dict[
                                        sheet_key(sheet, parent_name + key + "/0/" + k)
                                    ] = _(
                                        "WARNING: More than one value supplied, consult the relevant sub-sheet for the data."
                                    )

                    if (
                        self.use_titles
                        and self.schema_parser
                        and (parent_name, key,) in self.schema_parser.sub_sheet_titles
                    ):
                        sub_sheet_name = self.schema_parser.sub_sheet_titles[
                            (parent_name, key,)
                        ]
                    else:

# Path: flattentool/i18n.py
# def _(text):
#     lang = get_language()
#     if lang not in translations:
#         lang = "en"
#     return translations[lang].gettext(text)
# 
# Path: flattentool/input.py
# def path_search(
#     nested_dict, path_list, id_fields=None, path=None, top=False, top_sheet=False
# ):
#     if not path_list:
#         return nested_dict
# 
#     id_fields = id_fields or {}
#     parent_field = path_list[0]
#     path = parent_field if path is None else path + "/" + parent_field
# 
#     if parent_field.endswith("[]") or top:
#         if parent_field.endswith("[]"):
#             parent_field = parent_field[:-2]
#         if parent_field not in nested_dict:
#             nested_dict[parent_field] = TemporaryDict(
#                 keyfield=id_name, top_sheet=top_sheet, xml=xml  # noqa
#             )
#         sub_sheet_id = id_fields.get(path + "/id")
#         if sub_sheet_id not in nested_dict[parent_field]:
#             nested_dict[parent_field][sub_sheet_id] = {}
#         return path_search(
#             nested_dict[parent_field][sub_sheet_id],
#             path_list[1:],
#             id_fields=id_fields,
#             path=path,
#             top_sheet=top_sheet,
#         )
#     else:
#         if parent_field not in nested_dict:
#             nested_dict[parent_field] = OrderedDict()
#         return path_search(
#             nested_dict[parent_field],
#             path_list[1:],
#             id_fields=id_fields,
#             path=path,
#             top_sheet=top_sheet,
#         )
# 
# Path: flattentool/schema.py
# def make_sub_sheet_name(
#     parent_path, property_name, truncation_length=3, path_separator="/"
# ):
#     return (
#         "_".join(
#             x[:truncation_length] for x in parent_path.split(path_separator) if x != "0"
#         )
#         + property_name
#     )[:31]
# 
# Path: flattentool/sheet.py
# class PersistentSheet(Sheet):
#     """
#     A sheet that is persisted in ZODB database.
# 
#     """
# 
#     def __init__(self, columns=None, root_id="", name=None, connection=None):
#         super().__init__(columns=columns, root_id=root_id, name=name)
#         self.connection = connection
#         self.index = 0
#         # Integer key and object value btree.  Store sequential index in order to preserve input order.
#         connection.root.sheet_store[self.name] = BTrees.IOBTree.BTree()
# 
#     @property
#     def lines(self):
#         # btrees iterate in key order.
#         for key, value in self.connection.root.sheet_store[self.name].items():
#             # 5000 chosen by trial and error.  The written row
#             # data is removed from memory as is no loner needed.
#             # All new sheets clear out previous sheets data from memory.
#             if key % 5000 == 0:
#                 self.connection.cacheMinimize()
#             yield value
# 
#     def append_line(self, flattened_dict):
#         self.connection.root.sheet_store[self.name][self.index] = flattened_dict
#         self.index += 1
# 
#     @classmethod
#     def from_sheet(cls, sheet, connection):
#         instance = cls(name=sheet.name, connection=connection)
#         instance.id_columns = copy.deepcopy(sheet.id_columns)
#         instance.columns = copy.deepcopy(sheet.columns)
#         instance.titles = copy.deepcopy(sheet.titles)
#         instance.root_id = sheet.root_id
#         return instance


# Path: flattentool/json_input.py
import codecs
import copy
import os
import tempfile
import uuid
import BTrees.OOBTree
import ijson
import transaction
import xmltodict
import zc.zlibstorage
import ZODB.FileStorage
from collections import OrderedDict
from decimal import Decimal
from warnings import warn
from flattentool.i18n import _
from flattentool.input import path_search
from flattentool.schema import make_sub_sheet_name
from flattentool.sheet import PersistentSheet

                                        _(
                                            'More than one value supplied for "{}". Could not provide rollup, so adding a warning to the relevant cell(s) in the spreadsheet.'
                                        ).format(parent_name + key)
                                    )
                                    flattened_dict[
                                        sheet_key(sheet, parent_name + key + "/0/" + k)
                                    ] = _(
                                        "WARNING: More than one value supplied, consult the relevant sub-sheet for the data."
                                    )
                                elif parent_name + key in self.rollup:
                                    warn(
                                        _(
                                            'More than one value supplied for "{}". Could not provide rollup, so adding a warning to the relevant cell(s) in the spreadsheet.'
                                        ).format(parent_name + key)
                                    )
                                    flattened_dict[
                                        sheet_key(sheet, parent_name + key + "/0/" + k)
                                    ] = _(
                                        "WARNING: More than one value supplied, consult the relevant sub-sheet for the data."
                                    )

                    if (
                        self.use_titles
                        and self.schema_parser
                        and (parent_name, key,) in self.schema_parser.sub_sheet_titles
                    ):
                        sub_sheet_name = self.schema_parser.sub_sheet_titles[
                            (parent_name, key,)
                        ]
                    else:

                        sub_sheet_name = make_sub_sheet_name(