mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-29 12:24:45 +00:00
Update repl_server.py
This commit is contained in:
parent
dd6a409dcc
commit
ad0aaf49b9
1 changed files with 6 additions and 5 deletions
|
@ -1,4 +1,5 @@
|
|||
# Append __ to all variables to prevent name collisions in exec
|
||||
# All strings must be quoted by single quotes to prevent shell interpretation
|
||||
import socket as __socket
|
||||
import sys as __sys
|
||||
import importlib as __importlib
|
||||
|
@ -10,25 +11,25 @@ __server_socket.listen(1)
|
|||
(__client_socket, __client_address) = __server_socket.accept()
|
||||
|
||||
__already_loaded = False
|
||||
__res = ""
|
||||
__res = ''
|
||||
|
||||
while True:
|
||||
__order = __client_socket.recv(1024).decode()
|
||||
if __order == 'quit' or __order == 'exit':
|
||||
__client_socket.send("closed".encode())
|
||||
__client_socket.send('closed'.encode())
|
||||
break
|
||||
elif __order == 'load':
|
||||
__sys.stdout = __io.StringIO()
|
||||
if __already_loaded:
|
||||
__res = str(exec("__importlib.reload(o)"))
|
||||
__res = str(exec('__importlib.reload(o)'))
|
||||
else:
|
||||
__res = str(exec("import o"))
|
||||
__res = str(exec('import o'))
|
||||
__already_loaded = True
|
||||
__out = __sys.stdout.getvalue().strip()
|
||||
__res = __out + "\n" + __res
|
||||
__client_socket.send(__res.encode())
|
||||
else:
|
||||
__client_socket.send("unknown operation".encode())
|
||||
__client_socket.send('unknown operation'.encode())
|
||||
|
||||
__client_socket.close()
|
||||
__server_socket.close()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue