Commit 009a10a4 authored by augustin_s's avatar augustin_s 🐍
Browse files

refactor

parent 700eb1e7
......@@ -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)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment