This commit is contained in:
2022-05-10 10:26:01 +02:00
parent 700eb1e762
commit 009a10a4cd

12
pier.py
View File

@ -25,11 +25,7 @@ class ScriptServer(http.server.SimpleHTTPRequestHandler):
self.send_result(f"{scr} does not exist. choose from:\n", printable_scripts)
return
sio = StringIO()
with redirect_stdout(sio), redirect_stderr(sio):
with open(scr) as f:
exec(f.read())
res = sio.getvalue()
res = run_script(scr)
msg = f"{scr} output:\n"
msg += "_" * 80
@ -46,6 +42,12 @@ class ScriptServer(http.server.SimpleHTTPRequestHandler):
print(msg)
def run_script(fn):
sio = StringIO()
with redirect_stdout(sio), redirect_stderr(sio):
with open(fn) as f:
exec(f.read())
return sio.getvalue()
def encode_html(*msg):
msg = (str(i) for i in msg)