util.py (554B)
1 import os 2 from wptserve.pipes import template 3 4 # Returns the executor HTML (as bytes). 5 # `additional_script` (str) is inserted to the JavaScript before the executor. 6 def get_executor_html(request, additional_script): 7 content = template( 8 request, 9 open(os.path.join(os.path.dirname(__file__), "executor.sub.html"), "rb").read()) 10 11 # Insert an additional script at the head of script before Executor. 12 content = content.replace( 13 b'<script nonce="abc">', 14 b'<script nonce="abc">' + additional_script.encode('utf-8')) 15 16 return content