Commit 108953a8 authored by gac-cristall (Resp. Pedrini Bill Francesco)'s avatar gac-cristall (Resp. Pedrini Bill Francesco)
Browse files

added global/local namespace dicts for exec; added traceback print; return early for /

parent 27ec3e5b
......@@ -27,12 +27,16 @@ from io import StringIO
import os
import sys
import shlex
import traceback
import http.server
import socketserver
URL_SPACE = "%20"
exec_globals = {}
exec_locals = {}
class ScriptServer(http.server.SimpleHTTPRequestHandler):
......@@ -42,6 +46,7 @@ class ScriptServer(http.server.SimpleHTTPRequestHandler):
if not args:
super().do_GET()
return
scr = args[0]
......@@ -78,12 +83,13 @@ def run_script(fn, args):
code = open_script(fn)
old_sys_argv, sys.argv = sys.argv, args
try:
exec(code)
exec(code, exec_globals, exec_locals)
except BaseException as e: # need to catch SystemExit etc. as well
print("_" * 80)
tn = type(e).__name__
msg = f"{tn}: {e}"
print(msg, file=sys.stderr)
traceback.print_exc()
sys.argv = old_sys_argv
return sio.getvalue()
......
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