text
stringlengths 0
828
|
|---|
parsers[subclass] = self.__build_parser_for_fileobject_and_desiredtype(obj_on_filesystem,
|
object_typ=subclass,
|
logger=logger)
|
except NoParserFoundForObjectExt as e:
|
logger.warning(""{} - {}"".format(type(e).__name__, e))
|
errors[e] = e
|
except NoParserFoundForObjectType as f:
|
logger.warning(""{} - {}"".format(type(f).__name__, f))
|
errors[f] = f
|
if len(subclasses) > GLOBAL_CONFIG.dict_to_object_subclass_limit:
|
warn('Type {} has more than {} subclasses, only {} were tried to convert it, with no success. You '
|
'can raise this limit by setting the appropriate option with `parsyfiles_global_config()`'
|
''.format(object_typ, len(subclasses), GLOBAL_CONFIG.dict_to_object_subclass_limit))
|
return parsers"
|
502,"def __build_parser_for_fileobject_and_desiredtype(self, obj_on_filesystem: PersistedObject, object_typ: Type[T],
|
logger: Logger = None) -> Parser:
|
""""""
|
Builds from the registry, a parser to parse object obj_on_filesystem as an object of type object_type.
|
To do that, it iterates through all registered parsers in the list in reverse order (last inserted first),
|
and checks if they support the provided object format (single or multifile) and type.
|
If several parsers match, it returns a cascadingparser that will try them in order.
|
:param obj_on_filesystem:
|
:param object_typ:
|
:param logger:
|
:return:
|
""""""
|
# first remove any non-generic customization
|
object_type = get_base_generic_type(object_typ)
|
# find all matching parsers for this
|
matching, no_type_match_but_ext_match, no_ext_match_but_type_match, no_match = \
|
self.find_all_matching_parsers(strict=self.is_strict, desired_type=object_type,
|
required_ext=obj_on_filesystem.ext)
|
matching_parsers = matching[0] + matching[1] + matching[2]
|
if len(matching_parsers) == 0:
|
# No match. Do we have a close match ? (correct type, but not correct extension ?)
|
if len(no_ext_match_but_type_match) > 0:
|
raise NoParserFoundForObjectExt.create(obj_on_filesystem, object_type,
|
set([ext_ for ext_set in
|
[p.supported_exts for p in no_ext_match_but_type_match]
|
for ext_ in ext_set]))
|
else:
|
# no, no match at all
|
raise NoParserFoundForObjectType.create(obj_on_filesystem, object_type,
|
set([typ_ for typ_set in
|
[p.supported_types for p in no_type_match_but_ext_match]
|
for typ_ in typ_set]))
|
elif len(matching_parsers) == 1:
|
# return the match directly
|
return matching_parsers[0]
|
else:
|
# return a cascade of all parsers, in reverse order (since last is our preferred one)
|
# print('----- WARNING : Found several parsers able to parse this item. Combining them into a cascade.')
|
return CascadingParser(list(reversed(matching_parsers)))"
|
503,"def create(att_name: str, parsed_att: S, attribute_type: Type[T], caught_exec: Dict[Converter[S, T], 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 att_name:
|
:param parsed_att:
|
:param attribute_type:
|
:param caught_exec:
|
:return:
|
""""""
|
base_msg = ""Error while trying to convert value for attribute '{a}' to type <{t}>:\n"" \
|
"" - parsed value is : '{v}' of type <{tv}>\n"" \
|
"""".format(a=str(att_name), t=get_pretty_type_str(attribute_type), v=parsed_att,
|
tv=get_pretty_type_str(type(parsed_att)))
|
msg = StringIO()
|
if len(list(caught_exec.keys())) > 0:
|
msg.writelines(' - converters tried are : \n * ')
|
msg.writelines('\n * '.join([str(converter) for converter in caught_exec.keys()]))
|
msg.writelines(' \n Caught the following exceptions: \n')
|
for converter, err in caught_exec.items():
|
msg.writelines('--------------- From ' + str(converter) + ' caught: \n')
|
print_error_to_io_stream(err, msg)
|
msg.write('\n')
|
return AttrConversionException(base_msg + msg.getvalue())"
|
504,"def create(conversion_finder, parsed_att: Any, attribute_type: Type[Any], errors: Dict[Type, Exception] = None):
|
""""""
|
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 parsed_att:
|
:param attribute_type:
|
:param conversion_finder:
|
:return:
|
""""""
|
if conversion_finder is None:
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.