text
stringlengths 0
828
|
|---|
:param obj_on_fs_to_parse:
|
:param desired_type:
|
:param log_only_last: a flag to only log the last part of the file path (default False). Note that this can be
|
overriden by a global configuration 'full_paths_in_logs'
|
:param parser:
|
:return:
|
""""""
|
loc = obj_on_fs_to_parse.get_pretty_location(blank_parent_part=(log_only_last
|
and not GLOBAL_CONFIG.full_paths_in_logs),
|
compact_file_ext=True)
|
return '{loc} -> {type} ------- using {parser}'.format(loc=loc, type=get_pretty_type_str(desired_type),
|
parser=str(parser))"
|
712,"def is_able_to_parse_detailed(self, desired_type: Type[Any], desired_ext: str, strict: bool) -> Tuple[bool, bool]:
|
""""""
|
Utility method to check if a parser is able to parse a given type, either in
|
* strict mode (desired_type must be one of the supported ones, or the parser should be generic)
|
* inference mode (non-strict) : desired_type may be a parent class of one the parser is able to produce
|
:param desired_type: the type of the object that should be parsed,
|
:param desired_ext: the file extension that should be parsed
|
:param strict: a boolean indicating whether to evaluate in strict mode or not
|
:return: a first boolean indicating if there was a match, and a second boolean indicating if that match was
|
strict (None if no match)
|
""""""
|
# (1) first handle the easy joker+joker case
|
if desired_ext is JOKER and desired_type is JOKER:
|
return True, None
|
# (2) if ext is not a joker we can quickly check if it is supported
|
if desired_ext is not JOKER:
|
check_var(desired_ext, var_types=str, var_name='desired_ext')
|
if desired_ext not in self.supported_exts:
|
# ** no match on extension - no need to go further
|
return False, None
|
# (3) if type=joker and ext is supported => easy
|
if desired_type is JOKER:
|
# ** only extension match is required - ok.
|
return True, None
|
# (4) at this point, ext is JOKER OR supported and type is not JOKER. Check type match
|
check_var(desired_type, var_types=type, var_name='desired_type_of_output')
|
check_var(strict, var_types=bool, var_name='strict')
|
# -- first call custom checker if provided
|
if self.is_able_to_parse_func is not None and not self.is_able_to_parse_func(strict, desired_type):
|
return False, None
|
# -- strict match : either the parser is able to parse Anything, or the type is in the list of supported types
|
if self.is_generic() or (desired_type in self.supported_types):
|
return True, True # exact match
|
# -- non-strict match : if the parser is able to parse a subclass of the desired type, it is ok
|
elif (not strict) \
|
and any(issubclass(supported, desired_type) for supported in self.supported_types):
|
return True, False # approx match
|
# -- no match at all
|
else:
|
return False, None"
|
713,"def are_worth_chaining(parser, to_type: Type[S], converter: Converter[S, T]) -> bool:
|
""""""
|
Utility method to check if it makes sense to chain this parser with the given destination type, and the given
|
converter to create a parsing chain. Returns True if it brings value to chain them.
|
To bring value,
|
* the converter's output should not be a parent class of the parser's output. Otherwise
|
the chain does not even make any progress :)
|
* The parser has to allow chaining (with converter.can_chain=True)
|
:param parser:
|
:param to_type:
|
:param converter:
|
:return:
|
""""""
|
if not parser.can_chain:
|
# The base parser prevents chaining
|
return False
|
elif not is_any_type(to_type) and is_any_type(converter.to_type):
|
# we gain the capability to generate any type. So it is interesting.
|
return True
|
elif issubclass(to_type, converter.to_type):
|
# Not interesting : the outcome of the chain would be not better than one of the parser alone
|
return False
|
# Note: we dont say that chaining a generic parser with a converter is useless. Indeed it might unlock some
|
# capabilities for the user (new file extensions, etc.) that would not be available with the generic parser
|
# targetting to_type alone. For example parsing object A from its constructor then converting A to B might
|
# sometimes be interesting, rather than parsing B from its constructor
|
else:
|
# Interesting
|
return True"
|
714,"def create_for_caught_error(parser: _BaseParserDeclarationForRegistries, desired_type: Type[T],
|
obj: PersistedObject, caught: Exception, options: Dict[str, Dict[str, Any]]):
|
""""""
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.