def __format_value(cls, value, context, start_key):
if value is NotImplemented:
raise NotImplementedError
if isinstance(value, six.string_types):
for key in cls._string_format_regex.findall(value):
if key == start_key:
raise errors.ValueSubstitutionInfiniteLoopError
context[key] = cls.__format_value(
context[key], context, start_key)
return value.format(**context)
if isinstance(value, Mapping):
return OrderedDict(
(k, cls.__format_value(v, context, start_key)) for k, v in value.items())
if isinstance(value, Sequence):
return [cls.__format_value(v, context, start_key) for v in value]
return value
评论列表
文章目录