text
stringlengths
0
828
return pp"
1223,"def _create_parsing_plan(self, desired_type: Type[T], filesystem_object: PersistedObject, logger: Logger,
log_only_last: bool = False):
""""""
Adds a log message and creates a recursive 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:
""""""
logger.debug('(B) ' + get_parsing_plan_log_str(filesystem_object, desired_type,
log_only_last=log_only_last, parser=self))
return AnyParser._RecursiveParsingPlan(desired_type, filesystem_object, self, logger)"
1224,"def _get_parsing_plan_for_multifile_children(self, obj_on_fs: PersistedObject, desired_type: Type[T],
logger: Logger) -> Dict[str, ParsingPlan[T]]:
""""""
This method is called by the _RecursiveParsingPlan when created.
Implementing classes should return a dictionary containing a ParsingPlan for each child they plan to parse
using this framework. Note that for the files that will be parsed using a parsing library it is not necessary to
return a ParsingPlan.
In other words, implementing classes should return here everything they need for their implementation of
_parse_multifile to succeed. Indeed during parsing execution, the framework will call their _parse_multifile
method with that same dictionary as an argument (argument name is 'parsing_plan_for_children', see _BaseParser).
:param obj_on_fs:
:param desired_type:
:param logger:
:return:
""""""
pass"
1225,"def _parse_singlefile(self, desired_type: Type[T], file_path: str, encoding: str, logger: Logger,
options: Dict[str, Dict[str, Any]]) -> T:
""""""
Implementation of the parent method : since this is a multifile parser, this is not implemented.
:param desired_type:
:param file_path:
:param encoding:
:param logger:
:param options:
:return:
""""""
raise Exception('Not implemented since this is a MultiFileParser')"
1226,"def create(parser_func: Union[ParsingMethodForStream, ParsingMethodForFile], caught: Exception):
""""""
Helper method provided because we actually can't put that in the constructor, it creates a bug in Nose tests
ERROR: type should be string, got " https://github.com/nose-devs/nose/issues/725"
:param parser_func:
:param caught:
:return:
""""""
msg = 'Caught TypeError while calling parsing function \'' + str(parser_func.__name__) + '\'. ' \
'Note that the parsing function signature should be ' + parsing_method_stream_example_signature_str \
+ ' (streaming=True) or ' + parsing_method_file_example_signature_str + ' (streaming=False).' \
'Caught error message is : ' + caught.__class__.__name__ + ' : ' + str(caught)
return CaughtTypeError(msg).with_traceback(caught.__traceback__)"
1227,"def _parse_singlefile(self, desired_type: Type[T], file_path: str, encoding: str, logger: Logger,
options: Dict[str, Dict[str, Any]]) -> T:
""""""
Relies on the inner parsing function to parse the file.
If _streaming_mode is True, the file will be opened and closed by this method. Otherwise the parsing function
will be responsible to open and close.
:param desired_type:
:param file_path:
:param encoding:
:param options:
:return:
""""""
opts = get_options_for_id(options, self.get_id_for_options())
if self._streaming_mode:
# We open the stream, and let the function parse from it
file_stream = None
try:
# Open the file with the appropriate encoding
file_stream = open(file_path, 'r', encoding=encoding)
# Apply the parsing function
if self.function_args is None:
return self._parser_func(desired_type, file_stream, logger, **opts)
else:
return self._parser_func(desired_type, file_stream, logger, **self.function_args, **opts)
except TypeError as e:
raise CaughtTypeError.create(self._parser_func, e)
finally:
if file_stream is not None:
# Close the File in any case
file_stream.close()
else:
# the parsing function will open the file itself
if self.function_args is None: