text stringlengths 0 828 |
|---|
:param strict_type_matching: |
:return: |
"""""" |
check_var(strict_type_matching, var_types=bool, var_name='strict_matching') |
res = dict() |
# For all extensions that are supported, |
for ext in self.get_all_supported_exts_for_type(type_to_match=JOKER, strict=strict_type_matching): |
res[ext] = self.get_capabilities_for_ext(ext, strict_type_matching) |
return res" |
493,"def get_capabilities_for_ext(self, ext, strict_type_matching: bool = False) -> Dict[Type, Dict[str, Parser]]: |
"""""" |
Utility method to return, for a given file extension, all known ways to parse a file with this extension, |
organized by target object type. |
:param ext: |
:param strict_type_matching: |
:return: |
"""""" |
r = dict() |
# List all types that can be parsed from this extension. |
for typ in self.get_all_supported_types_for_ext(ext): |
# Use the query to fill |
matching = self.find_all_matching_parsers(strict_type_matching, desired_type=typ, required_ext=ext)[0] |
# matching_list = matching[0] + matching[1] + matching[2] |
# insert_element_to_dict_of_dicts_of_list(res, ext, typ, list(reversed(matching_list))) |
r[typ] = dict() |
exact = list(reversed(matching[2])) |
if len(exact) > 0: |
r[typ]['1_exact_match'] = exact |
approx = list(reversed(matching[1])) |
if len(approx) > 0: |
r[typ]['2_approx_match'] = approx |
generic = list(reversed(matching[0])) |
if len(generic) > 0: |
r[typ]['3_generic'] = generic |
# insert_element_to_dict_of_dicts(res, ext, typ, matching_dict) |
return r" |
494,"def register_parser(self, parser: Parser): |
"""""" |
Utility method to register any parser. Parsers that support any type will be stored in the ""generic"" |
list, and the others will be stored in front of the types they support |
:return: |
"""""" |
check_var(parser, var_types=Parser, var_name='parser') |
if (not parser.supports_multifile()) and (not parser.supports_singlefile()): |
# invalid |
raise _InvalidParserException.create(parser) |
# (0) sanity check : check that parser handles jokers properly |
res = parser.is_able_to_parse_detailed(desired_type=JOKER, desired_ext=JOKER, strict=True) |
if not (res[0] is True and res[1] is None): |
raise ValueError('Parser ' + str(parser) + ' can not be registered since it does not handle the JOKER cases ' |
'correctly') |
# (1) store in the main lists |
if parser.is_generic(): |
self._generic_parsers.append(parser) |
else: |
self._specific_parsers.append(parser) |
# (2) simpler : simply store the ext <> type maps |
for ext in parser.supported_exts: |
for typ in parser.supported_types: |
insert_element_to_dict_of_list(self._strict_types_to_ext, typ, ext) |
insert_element_to_dict_of_list(self._ext_to_strict_types, ext, typ)" |
495,"def get_all_parsers(self, strict_type_matching: bool = False) -> List[Parser]: |
"""""" |
Returns the list of all parsers in order of relevance. |
:return: |
"""""" |
matching = self.find_all_matching_parsers(strict=strict_type_matching)[0] |
# matching[1] (approx match) is supposed to be empty since we use a joker on type and a joker on ext : only |
# exact and generic match should exist, no approx match |
if len(matching[1]) > 0: |
raise Exception('Internal error - this matching[1] list is supposed to be empty for such a query') |
return matching[0] + matching[2]" |
496,"def get_all_supported_types_for_ext(self, ext_to_match: str, strict_type_matching: bool = False) -> Set[Type]: |
"""""" |
Utility method to return the set of all supported types that may be parsed from files with the given extension. |
ext=JOKER is a joker that means all extensions |
:param ext_to_match: |
:param strict_type_matching: |
:return: |
"""""" |
matching = self.find_all_matching_parsers(required_ext=ext_to_match, strict=strict_type_matching)[0] |
return {typ for types in [p.supported_types for p in (matching[0] + matching[1] + matching[2])] |
for typ in types}" |
497,"def get_all_supported_exts_for_type(self, type_to_match: Type[Any], strict: bool) -> Set[str]: |
"""""" |
Utility method to return the set of all supported file extensions that may be converted to objects of the given |
type. type=JOKER is a joker that means all types |
:param type_to_match: |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.