code: def apply_template(template, *args, **kw):
      
      if six.callable(template):
          return template(*args, **kw)
      if isinstance(template, six.string_types):
          return template
      if isinstance(template, collections.Mapping):
          return template.__class__((k, apply_template(v, *args, **kw)) for k, v in template.items())
      if isinstance(template, collections.Iterable):
          return template.__class__(apply_template(v, *args, **kw) for v in template)
      return template
docs: Applies every callable in any Mapping or Iterable