import urllib def inline(doc, doctype="html", mime="text/html;charset=utf-8"): if doctype == "html": mime = "text/html;charset=utf-8" elif doctype == "xhtml": mime = "application/xhtml+xml" doc = r""" XHTML might be the future {} """.format(doc) return "data:{},{}".format(mime, urllib.quote(doc))