mò &U²Ic@s dZdkZdkZdkZdkZdkZdkZdkZdk Z dk Z dk Z dk Z dk Z dkZd„Zd„Ze ie ieeƒddZdZdeifd„ƒYZhZe i d ƒZe i d ƒZd fd „ƒYZd fd „ƒYZd„Zdfd„ƒYZdeiefd„ƒYZdefd„ƒYZdfd„ƒYZ d„Z!d„Z"dfd„ƒYZ#dS(sRPC Implemention, originally written for the Python Idle IDE For security reasons, GvR requested that Idle's Python execution server process connect to the Idle process, which listens for the connection. Since Idle has has only one client per server, this was not a limitation. +---------------------------------+ +-------------+ | SocketServer.BaseRequestHandler | | SocketIO | +---------------------------------+ +-------------+ ^ | register() | | | unregister()| | +-------------+ | ^ ^ | | | | + -------------------+ | | | | +-------------------------+ +-----------------+ | RPCHandler | | RPCClient | | [attribute of RPCServer]| | | +-------------------------+ +-----------------+ The RPCServer handler class is expected to provide register/unregister methods. RPCHandler inherits the mix-in class SocketIO, which provides these methods. See the Idle run.main() docstring for further information on how this was accomplished in Idle. NcCsti|ƒ}|S(N(tmarshaltloadstmstco(RR((t(/data/zmath/lib/python2.4/idlelib/rpc.pyt unpickle_code-scCsti|ƒ}t|ffS(N(RtdumpsRRR(RR((Rt pickle_code2siis 127.0.0.1t RPCServercBs8tZdd„Zd„Zd„Zd„Zd„ZRS(NcCs1|djo t}ntii|||ƒdS(N(t handlerclasstNonet RPCHandlert SocketServert TCPServert__init__tselftaddr(RRR ((RRGs  cCsdS(s@Override TCPServer method, no bind() phase for connecting entityN((R((Rt server_bindLscCs|ii|iƒdS(sÎOverride TCPServer method, connect() instead of listen() Due to the reversed connection, self.server_address is actually the address of the Idle Client to which we are connecting. N(Rtsockettconnecttserver_address(R((Rtserver_activatePscCs|i|ifS(s:Override TCPServer method, return already connected socketN(RRR(R((Rt get_requestYsc CsÄy‚Wn¶tj o ‚n¢ti}|dddIJ|dIJ|dtiƒiƒIJ|dI|IJ|dIt|ƒIJt i d|ƒ|d IJ|ddIJt i d ƒnXd S( sÜOverride TCPServer method Error message goes to __stderr__. No error message if exiting normally or socket raised EOF. Other exceptions not handled in server code will cause os._exit. s t-i(sUnhandled server exception!s Thread: %ssClient Address: s Request: tfiles# *** Unrecoverable, server exiting!iN(t SystemExittsyst __stderr__terft threadingt currentThreadtgetNametclient_addresstreprtrequestt tracebackt print_exctost_exit(RR"R R((Rt handle_error]s    (t__name__t __module__R RRRRR'(((RREs    itSocketIOcBstZdZddd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„Zd„Zd„Zd„Zd„Zd„Zd„ZdZdZdZd„Zd„Zd„Zd„Zd„Zd„Z d„Z!RS(NicCshtiƒ|_|dj o ||_n||_|djo t}n||_h|_ h|_ dS(N( RRRt sockthreadt debuggingR tsocktobjtablet objecttablet responsestcvars(RR-R.R,((RR€s       cCs1|i}d|_|dj o|iƒndS(N(RR-R tclose(RR-((RR2‹s   cCstiƒdS(s!override for specific exit actionN(R%R&(R((Rtexithook‘scGsk|ipdSn|idttiƒiƒƒ}x"|D]}|dt|ƒ}q<Wt i |IJdS(Nt ( RR,tlocationtstrRRRtstargstaRR(RR8R9R7((Rtdebug•s #cCs||i|t i g|iggƒ\}}}|ii|t ƒ}Wn"ttifj o t‚q|X||}q|WdS(Nsputmessage:%d:isCannot pickle:s}|i|}|iƒd|i|<|i ƒ|i ƒq!W|i ƒdS(s+action taken upon link being closed by peerR RkN(sEOFN( RtEOFhookR:R1tkeyR¢R|R R0R£R}R3(RR¢R¥((RR Ës       cCsdS(sBClasses using rpc client/server can override to augment EOF actionN((R((RR¤Øs("R(R)R~R RR2R3R:R=R?R]R`RbR^RaR_RjRmRsRhRuRtRcRfRRR•R”RŽR“RšR{R R¤(((RR*|s>      (               I RWcBstZRS(N(R(R)(((RRWÞscCs t|ƒ}|t|t|ƒD]0}t||ƒ}t|ƒod||t|ƒD]0}t||ƒ}t|ƒpd||