Reverse the RPC socket connection: Python execution server connects to

Idle client and localhost origin of connection is verified by client.
M PyShell.py
M rpc.py
M run.py
This commit is contained in:
Kurt B. Kaiser 2002-07-26 00:06:42 +00:00
parent db40afaabe
commit b417936d40
3 changed files with 110 additions and 71 deletions

View file

@ -1,13 +1,44 @@
import sys
import time
import socket
import rpc
def main():
"""Start the Python execution server in a subprocess
In Idle, RPCServer is instantiated with handlerclass MyHandler, which
inherits register/unregister methods from RPCHandler via the mix-in class
SocketIO.
When the RPCServer is instantiated, the TCPServer initialization creates an
instance of run.MyHandler and calls its handle() method. handle()
instantiates a run.Executive, passing it a reference to the MyHandler
object. That reference is saved as an attribute of the Executive instance.
The Executive methods have access to the reference and can pass it on to
entities that they command (e.g. RemoteDebugger.Debugger.start_debugger()).
The latter, in turn, can call MyHandler(SocketIO) register/unregister
methods via the reference to register and unregister themselves.
"""
port = 8833
if sys.argv[1:]:
port = int(sys.argv[1])
sys.argv[:] = [""]
addr = ("localhost", port)
svr = rpc.RPCServer(addr, MyHandler)
for i in range(12):
time.sleep(i)
try:
svr = rpc.RPCServer(addr, MyHandler)
break
except socket.error, err:
if i < 5:
print>>sys.__stderr__, ".. ",
else:
print>>sys.__stderr__,"\nPython subprocess socket error: "\
+ err[1] + ", retrying...."
else:
print>>sys.__stderr__, "\nConnection to Idle failed, exiting."
sys.exit()
svr.handle_request() # A single request only
class MyHandler(rpc.RPCHandler):