text
stringlengths
0
828
specific_chains += new_c_at_beginning
specific_nonstrict_chains += new_c_at_beginning_ns
# by combining all created chains into a big one
for a in new_c_at_end:
for b in new_c_at_beginning:
b_ = b.remove_first()
if b_.can_be_appended_to(a, strict=True):
if ConversionChain.are_worth_chaining(a, b_):
specific_chains.append(ConversionChain.chain(a, b_, strict=True))
for b in new_c_at_beginning_ns:
b_ = b.remove_first()
if b_.can_be_appended_to(a, strict=False):
if ConversionChain.are_worth_chaining(a, b_):
specific_nonstrict_chains.append(ConversionChain.chain(a, b_, strict=False))
for a in new_c_at_end_ns:
for b in (new_c_at_beginning_ns + new_c_at_beginning):
b_ = b.remove_first()
if b_.can_be_appended_to(a, strict=False):
if ConversionChain.are_worth_chaining(a, b_):
specific_nonstrict_chains.append(ConversionChain.chain(a, b_, strict=False))
# by inserting this converter at the beginning of an existing *generic*
if converter.is_generic():
# we want to avoid chaining generic converters together
pass
else:
new_c_at_beginning_generic = []
new_c_at_beginning_generic_ns = []
for existing_specific in self._generic_conversion_chains:
# start with strict
if existing_specific.can_be_appended_to(converter, strict=True):
if ConversionChain.are_worth_chaining(converter, existing_specific):
new_c_at_beginning_generic.append(ConversionChain.chain(converter, existing_specific,
strict=True))
elif (not self.strict) and existing_specific.can_be_appended_to(converter, strict=False):
if ConversionChain.are_worth_chaining(converter, existing_specific):
new_c_at_beginning_generic_ns.append(ConversionChain.chain(converter, existing_specific,
strict=False))
for existing_specific_ns in self._generic_nonstrict_conversion_chains:
if existing_specific_ns.can_be_appended_to(converter, strict=False):
if ConversionChain.are_worth_chaining(converter, existing_specific_ns):
new_c_at_beginning_generic_ns.append(ConversionChain.chain(converter, existing_specific_ns,
strict=False))
generic_chains += new_c_at_beginning_generic
generic_nonstrict_chains += new_c_at_beginning_generic_ns
# by combining specific and generic created chains into a big one
for a in new_c_at_end:
for b in new_c_at_beginning_generic:
b_ = b.remove_first()
if b_.can_be_appended_to(a, strict=True):
if ConversionChain.are_worth_chaining(a, b_):
generic_chains.append(ConversionChain.chain(a, b_, strict=True))
for b in new_c_at_beginning_generic_ns:
b_ = b.remove_first()
if b_.can_be_appended_to(a, strict=False):
if ConversionChain.are_worth_chaining(a, b_):
generic_nonstrict_chains.append(ConversionChain.chain(a, b_, strict=False))
for a in new_c_at_end_ns:
for b in (new_c_at_beginning_generic_ns + new_c_at_beginning_generic):
b_ = b.remove_first()
if b_.can_be_appended_to(a, strict=False):
if ConversionChain.are_worth_chaining(a, b_):
generic_nonstrict_chains.append(ConversionChain.chain(a, b_, strict=False))
return generic_chains, generic_nonstrict_chains, specific_chains, specific_nonstrict_chains"
513,"def get_all_conversion_chains(self, from_type: Type[Any] = JOKER, to_type: Type[Any] = JOKER) \
-> Tuple[List[Converter], List[Converter], List[Converter]]:
""""""
Utility method to find matching converters or conversion chains.
:param from_type: a required type of input object, or JOKER for 'wildcard'(*) .
WARNING: ""from_type=AnyObject/object/Any"" means
""all converters able to source from anything"", which is different from ""from_type=JOKER"" which means ""all
converters whatever their source type"".
:param to_type: a required type of output object, or JOKER for 'wildcard'(*) .
WARNING: ""to_type=AnyObject/object/Any"" means ""all
converters able to produce any type of object"", which is different from ""to_type=JOKER"" which means ""all
converters whatever type they are able to produce"".
:return: a tuple of lists of matching converters, by type of *dest_type* match : generic, approximate, exact.
The order of each list is from *less relevant* to *most relevant*
""""""
if from_type is JOKER and to_type is JOKER:
matching_dest_generic = self._generic_nonstrict_conversion_chains.copy() + \
self._generic_conversion_chains.copy()
matching_dest_approx = []
matching_dest_exact = self._specific_non_strict_conversion_chains.copy() + \
self._specific_conversion_chains.copy()
else:
matching_dest_generic, matching_dest_approx, matching_dest_exact = [], [], []
# first transform any 'Any' type requirement into the official class for that
to_type = get_validated_type(to_type, 'to_type', enforce_not_joker=False)
# handle generic converters first
for c in (self._generic_nonstrict_conversion_chains + self._generic_conversion_chains):