m &UIc@sdZdkZdkZdkZdkZdkZdkZdkZdk Z dk Z dk Z dk Z dk Z dkZdZdZe ie ieeddZdZdeifdYZhZe i d Ze i d Zd fd YZd fd YZdZdfdYZdeiefdYZdefdYZdfdYZ dZ!dZ"dfdYZ#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. NcCs-ti|}t|tipt|S(N(tmarshaltloadstmstcot isinstancettypestCodeTypetAssertionError(RR((t(/data/zmath/lib/python2.4/idlelib/rpc.pyt unpickle_code-scCs6t|tiptti|}t|ffS(N( RRRRRRtdumpsRR (RR((Rt pickle_code2siis 127.0.0.1t RPCServercBs8tZddZdZdZdZdZRS(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|idS(sOverride 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 CsyWntj o nti}|dddIJ|dIJ|dtiiIJ|dI|IJ|dIt|IJt i d||d IJ|ddIJt i d nXd S( sOverride 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__RRRRRR+(((RR Es    itSocketIOcBstZdZdddZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!RS(NicCshti|_|dj o ||_n||_|djo t}n||_h|_ h|_ dS(N( R!R"Rt sockthreadt debuggingRtsocktobjtablet objecttablet responsestcvars(RR1R2R0((RRs       cCs1|i}d|_|dj o|indS(N(RR1Rtclose(RR1((RR6s   cCstidS(s!override for specific exit actionN(R)R*(R((RtexithookscGsk|ipdSn|idttii}x"|D]}|dt|}q<Wt i |IJdS(Nt ( RR0tlocationtstrR!R"R#tstargstaRR(RR<R=R;((Rtdebugs #cCs||i|R&thowR@t methodnameR<tkwargst TypeErrorR2thas_keytobjtmethodst _getmethodst attributest_getattributesthasattrtgetattrtmethodtretRt RemoteObjectt remotereft request_queuetputtseqRRRterrorR'R(RR( RR^R&RRRYRLRNRXR@R<RMRQRT((Rt localcallsJ         cCs8|id|||i||||}|i|S(Nsremotecall:asynccall: ( RR>R@RMt asynccallR<RNR^t asyncreturn(RR@RMR<RNR^((Rt remotecallscCs8|id|||i||||}|i|S(Nsremotequeue:asyncqueue: ( RR>R@RMt asyncqueueR<RNR^Rb(RR@RMR<RNR^((Rt remotequeuescCsd||||ff}|i}ti |i joti }||i |t putmessage(RR@RMR<RNRhR^R&((RRas  cCsd||||ff}|i}ti |i joti }||i |Ri(RR@RMR<RNRhR^R&((RRds  cCsG|id||i|dd}|id|||i|S(Ns#asyncreturn:%d:call getresponse(): twaitf0.050000000000000003sasyncreturn:%d:response: (RR>R^t getresponsetresponsetdecoderesponse(RR^Rl((RRbscCs|\}}|djo|Sn|djodSn|djo|iddSn|djo|id|idSn|djo|id|t|nt||fdS( NRFRJRKsdecoderesponse: EXCEPTIONtEOFsdecoderesponse: EOFRDsdecoderesponse: Internal ERROR:( RlRLtwhatRRR>tdecode_interrupthookt RuntimeErrort SystemError(RRlRoRL((RRms           cCs tdS(tN(tEOFError(R((RRpscCsEy|iddddWn$tj o|iddSnXdS(sListen on socket until I/O not ready or EOF pollresponse() will loop looking for seq number None, which never comes, and exit on EOFError. tmyseqRjf0.050000000000000003smainloop:returnN(RRkRRtR>(R((Rtmainloops  cCsY|i||}|dj o6|\}}|djo||i|f}qUn|S(NRF( Rt _getresponseRuRjRlRRLRot_proxify(RRuRjRoRLRl((RRks    cCsOt|tot||iSnt|tiot|i |Sn|S(N( RRQt RemoteProxytRPCProxyRR@RtListTypetmapRx(RRQ((RRxs cCs|id|ti|ijo3x|i||}|dj o|Sq)q)Wn|i |}|i x"|i i|p|iqsW|i |}|id||f|i |=|i |=|i|SdS(Ns_getresponse:myseq:is-_getresponse:%s: thread woke up: response: %s(RR>RuR!R"R/t pollresponseRjRlRR5RhtacquireR4RPtrelease(RRuRjRhRl((RRw%s$       cCs|id|_}|S(Ni(RtnextseqR^(RR^((RRf;scCs|id|dyti|}Wn2tij o#tidIt |IJnXt i dt ||}xt |djoqy>t i g|igg\}}}|ii|t }Wn"ttifj o tq|X||}q|WdS(Nsputmessage:%d:isCannot pickle:stmessagetpickleR R;t PicklingErrorRRR%tstructtpacktlentselectR1trtwtxtsendtBUFSIZEtntAttributeErrorRR_tIOError(RRRR;RRR((RRi?s$ RsicCs|it|i|ijoti|iiggg|\}}}t|djodSny|ii t}Wntij o tnXt|djo tn|i|7_|in|iS(Ni(Rt_stage0RtbuffertbufneedRR1tfilenoRjRRRRtrecvRR;RR_Rtt_stage1(RRjR;RRR((Rt pollpacketUs -  cCsm|idjoYt|idjoC|id }|id|_tid|d|_d|_ndS(NiisRuR`R5tcvR~R4tnotifyR( RRuRjR^RRRLRRRl((RR}sP                cCsq|i|idxI|iD]>}|i|}|id|i|<|i |i q!W|i dS(s+action taken upon link being closed by peerRRnN(sEOFN( RtEOFhookR>R5tkeyRR~RR4RRR7(RRR((RRs       cCsdS(sBClasses using rpc client/server can override to augment EOF actionN((R((RRs("R,R-RRRR6R7R>RARCR`RcReRaRdRbRmRpRvRkRxRwRfRiRRRRRRRR}RR(((RR.|s>      (               I RZcBstZRS(N(R,R-(((RRZscCs t|}|t|t|D]0}t||}t|od||t|D]0}t||}t|pd||