refactor
This commit is contained in:
12
pier.py
12
pier.py
@ -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)
|
||||
|
Reference in New Issue
Block a user