docs: def expand_template(template, namespace):
      """ Expand the given (preparsed) template.
          Currently, only Tempita templates are supported.
  
          @param template: The template, in preparsed form, or as a string (which then will be preparsed).
          @param namespace: Custom namespace that is added to the predefined defaults
              and takes precedence over those.
          @return: The expanded template.
          @raise LoggableError: In case of typical errors during template execution.
      """
      # Create helper namespace
      formatters = dict((name[4:], method)
          for name, method in globals().items()
          if name.startswith("fmt_")
      )
      helpers = Bunch()
      helpers.update(formatters)
  
      # Default templating namespace
      variables = dict(h=helpers, c=config.custom_template_helpers)
      variables.update(formatters)  # redundant, for backwards compatibility
  
      # Provided namespace takes precedence
      variables.update(namespace)
  
      # Expand template
      try:
          template = preparse(template)
          return template.substitute(**variables)
      except (AttributeError, ValueError, NameError, TypeError) as exc:
          hint = ''
          if "column" in str(exc):
              try:
                  col = int(str(exc).split("column")[1].split()[0])
              except (TypeError, ValueError):
                  pass
              else:
                  hint = "%svVv\n" % (' ' * (col+4))
  
          content = getattr(template, "content", template)
          raise error.LoggableError("%s: %s in template:\n%s%s" % (
              type(exc).__name__, exc, hint,
              "\n".join("%3d: %s" % (i+1, line) for i, line in enumerate(content.splitlines()))
          ))