docs: def generate_license(template, context):
      """ Generate a license by extracting variables from the template and
          replacing them with the corresponding values in the given context.
      """
      out = StringIO()
      content = template.getvalue()
      for key in extract_vars(template):
          if key not in context:
              raise ValueError("%s is missing from the template context" % key)
          content = content.replace("{{ %s }}" % key, context[key])
      template.close()  # free template memory (when is garbage collected?)
      out.write(content)
      return out