text
stringlengths 0
828
|
---|
return [SingleFileParserFunction(parser_function=read_dict_or_list_from_json,
|
streaming_mode=True, custom_name='read_dict_or_list_from_json',
|
supported_exts={'.json'},
|
supported_types={dict, list},
|
function_args={'conversion_finder': conversion_finder}),
|
MultifileCollectionParser(parser_finder)
|
]"
|
259,"def get_default_collection_converters(conversion_finder: ConversionFinder) -> List[Union[Converter[Any, dict], Converter[dict, Any]]]:
|
""""""
|
Utility method to return the default converters associated to dict (from dict to other type,
|
and from other type to dict)
|
:return:
|
""""""
|
return [ConverterFunction(from_type=List, to_type=Set, conversion_method=list_to_set, custom_name='list_to_set',
|
function_args={'conversion_finder': conversion_finder}),
|
ConverterFunction(from_type=List, to_type=Tuple, conversion_method=list_to_tuple,
|
custom_name='list_to_tuple', function_args={'conversion_finder': conversion_finder})]"
|
260,"def _get_parsing_plan_for_multifile_children(self, obj_on_fs: PersistedObject, desired_type: Type[Any],
|
logger: Logger) -> Dict[str, Any]:
|
""""""
|
Simply inspects the required type to find the base type expected for items of the collection,
|
and relies on the ParserFinder to find the parsing plan
|
:param obj_on_fs:
|
:param desired_type:
|
:param logger:
|
:return:
|
""""""
|
# nb of file children
|
n_children = len(obj_on_fs.get_multifile_children())
|
# first extract base collection type
|
subtypes, key_type = _extract_collection_base_type(desired_type)
|
if isinstance(subtypes, tuple):
|
# -- check the tuple length
|
if n_children != len(subtypes):
|
raise FolderAndFilesStructureError.create_for_multifile_tuple(obj_on_fs, len(subtypes),
|
len(obj_on_fs.get_multifile_children()))
|
else:
|
# -- repeat the subtype n times
|
subtypes = [subtypes] * n_children
|
# -- for each child create a plan with the appropriate parser
|
children_plan = OrderedDict()
|
# use sorting for reproducible results in case of multiple errors
|
for (child_name, child_fileobject), child_typ in zip(sorted(obj_on_fs.get_multifile_children().items()),
|
subtypes):
|
# -- use the parserfinder to find the plan
|
t, child_parser = self.parser_finder.build_parser_for_fileobject_and_desiredtype(child_fileobject,
|
child_typ, logger)
|
children_plan[child_name] = child_parser.create_parsing_plan(t, child_fileobject, logger,
|
_main_call=False)
|
return children_plan"
|
261,"def _parse_multifile(self, desired_type: Type[Union[Dict, List, Set, Tuple]], obj: PersistedObject,
|
parsing_plan_for_children: Dict[str, ParsingPlan], logger: Logger,
|
options: Dict[str, Dict[str, Any]]) \
|
-> Union[Dict, List, Set, Tuple]:
|
""""""
|
Options may contain a section with id 'MultifileCollectionParser' containing the following options:
|
* lazy_parsing: if True, the method will return immediately without parsing all the contents. Instead, the
|
returned collection will perform the parsing the first time an item is required.
|
* background_parsing: if True, the method will return immediately while a thread parses all the contents in
|
the background. Note that users cannot set both lazy_parsing and background_parsing to True at the same time
|
:param desired_type:
|
:param obj:
|
:param parsing_plan_for_children:
|
:param logger:
|
:param options:
|
:return:
|
""""""
|
# first get the options and check them
|
lazy_parsing = False
|
background_parsing = False
|
opts = self._get_applicable_options(options)
|
for opt_key, opt_val in opts.items():
|
if opt_key is 'lazy_parsing':
|
lazy_parsing = opt_val
|
elif opt_key is 'background_parsing':
|
background_parsing = opt_val
|
else:
|
raise Exception('Invalid option in MultiFileCollectionParser : ' + opt_key)
|
check_var(lazy_parsing, var_types=bool, var_name='lazy_parsing')
|
check_var(background_parsing, var_types=bool, var_name='background_parsing')
|
if lazy_parsing and background_parsing:
|
raise ValueError('lazy_parsing and background_parsing cannot be set to true at the same time')
|
if lazy_parsing:
|
# build a lazy dictionary
|
results = LazyDictionary(sorted(list(parsing_plan_for_children.keys())),
|
loading_method=lambda x: parsing_plan_for_children[x].execute(logger, options))
|
# logger.debug('Assembling a ' + get_pretty_type_str(desired_type) + ' from all children of ' + str(obj)
|
# + ' (lazy parsing: children will be parsed when used) ')
|
logger.debug('(P) {loc} : lazy parsing ON, children will be parsed only if/when used'.format(
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.