text
stringlengths
0
828
""""""
Utility method to remove the first converter of this chain. If inplace is True, this object is modified and
None is returned. Otherwise, a copy is returned
:param inplace: boolean indicating whether to modify this object (True) or return a copy (False)
:return: None or a copy with the first converter removed
""""""
if len(self._converters_list) > 1:
if inplace:
self._converters_list = self._converters_list[1:]
# update the current source type
self.from_type = self._converters_list[0].from_type
return
else:
new = copy(self)
new._converters_list = new._converters_list[1:]
# update the current source type
new.from_type = new._converters_list[0].from_type
return new
else:
raise ValueError('cant remove first: would make it empty!')"
1630,"def add_conversion_steps(self, converters: List[Converter], inplace: bool = False):
""""""
Utility method to add converters to this chain. If inplace is True, this object is modified and
None is returned. Otherwise, a copy is returned
:param converters: the list of converters to add
:param inplace: boolean indicating whether to modify this object (True) or return a copy (False)
:return: None or a copy with the converters added
""""""
check_var(converters, var_types=list, min_len=1)
if inplace:
for converter in converters:
self.add_conversion_step(converter, inplace=True)
else:
new = copy(self)
new.add_conversion_steps(converters, inplace=True)
return new"
1631,"def add_conversion_step(self, converter: Converter[S, T], inplace: bool = False):
""""""
Utility method to add a converter to this chain. If inplace is True, this object is modified and
None is returned. Otherwise, a copy is returned
:param converter: the converter to add
:param inplace: boolean indicating whether to modify this object (True) or return a copy (False)
:return: None or a copy with the converter added
""""""
# it the current chain is generic, raise an error
if self.is_generic() and converter.is_generic():
raise ValueError('Cannot chain this generic converter chain to the provided converter : it is generic too!')
# if the current chain is able to transform its input into a valid input for the new converter
elif converter.can_be_appended_to(self, self.strict):
if inplace:
self._converters_list.append(converter)
# update the current destination type
self.to_type = converter.to_type
return
else:
new = copy(self)
new._converters_list.append(converter)
# update the current destination type
new.to_type = converter.to_type
return new
else:
raise TypeError('Cannnot register a converter on this conversion chain : source type \'' +
get_pretty_type_str(converter.from_type)
+ '\' is not compliant with current destination type of the chain : \'' +
get_pretty_type_str(self.to_type) + ' (this chain performs '
+ ('' if self.strict else 'non-') + 'strict mode matching)')"
1632,"def insert_conversion_steps_at_beginning(self, converters: List[Converter], inplace: bool = False):
""""""
Utility method to insert converters at the beginning ofthis chain. If inplace is True, this object is modified
and None is returned. Otherwise, a copy is returned
:param converters: the list of converters to insert
:param inplace: boolean indicating whether to modify this object (True) or return a copy (False)
:return: None or a copy with the converters added
""""""
if inplace:
for converter in reversed(converters):
self.insert_conversion_step_at_beginning(converter, inplace=True)
return
else:
new = copy(self)
for converter in reversed(converters):
# do inplace since it is a copy
new.insert_conversion_step_at_beginning(converter, inplace=True)
return new"
1633,"def _convert(self, desired_type: Type[T], obj: S, logger: Logger, options: Dict[str, Dict[str, Any]]) -> T:
""""""
Apply the converters of the chain in order to produce the desired result. Only the last converter will see the
'desired type', the others will be asked to produce their declared to_type.
:param desired_type:
:param obj:
:param logger:
:param options:
:return:
""""""