MCPcopy Create free account
hub / github.com/cztomczak/cefpython / html_to_data_uri

Function html_to_data_uri

examples/tutorial.py:91–106  ·  view source on GitHub ↗
(html, js_callback=None)

Source from the content-addressed store, hash-verified

89
90
91def html_to_data_uri(html, js_callback=None):
92 # This function is called in two ways:
93 # 1. From Python: in this case value is returned
94 # 2. From Javascript: in this case value cannot be returned because
95 # inter-process messaging is asynchronous, so must return value
96 # by calling js_callback.
97 html = html.encode("utf-8", "replace")
98 b64 = base64.b64encode(html).decode("utf-8", "replace")
99 ret = "data:text/html;base64,{data}".format(data=b64)
100 if js_callback:
101 js_print(js_callback.GetFrame().GetBrowser(),
102 "Python", "html_to_data_uri",
103 "Called from Javascript. Will call Javascript callback now.")
104 js_callback.Call(ret)
105 else:
106 return ret
107
108
109def set_global_handler():

Callers 1

mainFunction · 0.85

Calls 2

js_printFunction · 0.85
GetBrowserMethod · 0.80

Tested by

no test coverage detected