text
stringlengths 0
828
|
|---|
if self.supports_multifile():
|
if not parser.supports_multifile():
|
raise ValueError(
|
'Cannot add this parser to this parsing cascade : it does not match the rest of the cascades '
|
'configuration (multifile support)')
|
if AnyObject not in parser.supported_types:
|
if typ is None:
|
# in that case the expected types for this parser will be self.supported_types
|
if AnyObject in self.supported_types:
|
raise ValueError(
|
'Cannot add this parser to this parsing cascade : it does not match the rest of the cascades '
|
'configuration (the cascade supports any type while the parser only supports '
|
+ str(parser.supported_types) + ')')
|
else:
|
missing_types = set(self.supported_types) - set(parser.supported_types)
|
if len(missing_types) > 0:
|
raise ValueError(
|
'Cannot add this parser to this parsing cascade : it does not match the rest of the '
|
'cascades configuration (supported types should at least contain the supported types '
|
'already in place. The parser misses type(s) ' + str(missing_types) + ')')
|
else:
|
# a parser is added but with a specific type target (parallel cascade)
|
if typ == AnyObject:
|
raise ValueError(
|
'Cannot add this parser to this parsing cascade : it does not match the expected type ""Any"", '
|
'it only supports ' + str(parser.supported_types))
|
# else:
|
# if get_base_generic_type(typ) not in parser.supported_types:
|
# raise ValueError(
|
# 'Cannot add this parser to this parsing cascade : it does not match the expected type ' +
|
# str(typ) + ', it only supports ' + str(parser.supported_types))
|
missing_exts = set(self.supported_exts) - set(parser.supported_exts)
|
if len(missing_exts) > 0:
|
raise ValueError(
|
'Cannot add this parser to this parsing cascade : it does not match the rest of the cascades '
|
'configuration (supported extensions should at least contain the supported extensions already in '
|
'place. The parser misses extension(s) ' + str(missing_exts) + ')')
|
# finally add it
|
self._parsers_list.append((typ, parser))"
|
1238,"def _create_parsing_plan(self, desired_type: Type[T], filesystem_object: PersistedObject, logger: Logger,
|
log_only_last: bool = False) -> ParsingPlan[T]:
|
""""""
|
Creates a parsing plan to parse the given filesystem object into the given desired_type.
|
This overrides the method in AnyParser, in order to provide a 'cascading' parsing plan
|
:param desired_type:
|
:param filesystem_object:
|
:param logger:
|
:param log_only_last: a flag to only log the last part of the file path (default False)
|
:return:
|
""""""
|
# build the parsing plan
|
logger.debug('(B) ' + get_parsing_plan_log_str(filesystem_object, desired_type,
|
log_only_last=log_only_last, parser=self))
|
return CascadingParser.CascadingParsingPlan(desired_type, filesystem_object, self, self._parsers_list,
|
logger=logger)"
|
1239,"def _parse_singlefile(self, desired_type: Type[T], file_path: str, encoding: str, logger: Logger,
|
options: Dict[str, Dict[str, Any]]) -> T:
|
""""""
|
Implementation of AnyParser API
|
""""""
|
# first use the base parser to parse something compliant with the conversion chain
|
first = self._base_parser._parse_singlefile(self._converter.from_type, file_path, encoding,
|
logger, options)
|
# then apply the conversion chain
|
return self._converter.convert(desired_type, first, logger, options)"
|
1240,"def _get_parsing_plan_for_multifile_children(self, obj_on_fs: PersistedObject, desired_type: Type[Any],
|
logger: Logger) -> Dict[str, Any]:
|
""""""
|
Implementation of AnyParser API
|
""""""
|
return self._base_parser._get_parsing_plan_for_multifile_children(obj_on_fs, self._converter.from_type, logger)"
|
1241,"def _parse_multifile(self, desired_type: Type[T], obj: PersistedObject,
|
parsing_plan_for_children: Dict[str, ParsingPlan],
|
logger: Logger, options: Dict[str, Dict[str, Any]]) -> T:
|
""""""
|
Implementation of AnyParser API
|
""""""
|
# first use the base parser
|
# first = self._base_parser._parse_multifile(desired_type, obj, parsing_plan_for_children, logger, options)
|
first = self._base_parser._parse_multifile(self._converter.from_type, obj, parsing_plan_for_children, logger,
|
options)
|
# then apply the conversion chain
|
return self._converter.convert(desired_type, first, logger, options)"
|
1242,"def are_worth_chaining(base_parser: Parser, to_type: Type[S], converter: Converter[S,T]) -> bool:
|
""""""
|
Utility method to check if it makes sense to chain this parser configured with the given to_type, with this
|
converter. It is an extension of ConverterChain.are_worth_chaining
|
:param base_parser:
|
:param to_type:
|
:param converter:
|
:return:
|
""""""
|
if isinstance(converter, ConversionChain):
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.