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)
|
self.send_result(f"{scr} does not exist. choose from:\n", printable_scripts)
|
||||||
return
|
return
|
||||||
|
|
||||||
sio = StringIO()
|
res = run_script(scr)
|
||||||
with redirect_stdout(sio), redirect_stderr(sio):
|
|
||||||
with open(scr) as f:
|
|
||||||
exec(f.read())
|
|
||||||
res = sio.getvalue()
|
|
||||||
|
|
||||||
msg = f"{scr} output:\n"
|
msg = f"{scr} output:\n"
|
||||||
msg += "_" * 80
|
msg += "_" * 80
|
||||||
@ -46,6 +42,12 @@ class ScriptServer(http.server.SimpleHTTPRequestHandler):
|
|||||||
print(msg)
|
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):
|
def encode_html(*msg):
|
||||||
msg = (str(i) for i in msg)
|
msg = (str(i) for i in msg)
|
||||||
|
Reference in New Issue
Block a user