{fc@sdZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl Z ddlZdZdZe je jeeddZdZdejfd YZiZe j d Ze j d Zd efd YZd efdYZdZdefdYZdejefdYZdefdYZ defdYZ!dZ"dZ#defdYZ$dS(sRPC Implementation, 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 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. iNcCstj|}|S(N(tmarshaltloads(tmstco((s#/usr/lib64/python2.7/idlelib/rpc.pyt unpickle_code-scCstj|}t|ffS(N(RtdumpsR(RR((s#/usr/lib64/python2.7/idlelib/rpc.pyt pickle_code2siis 127.0.0.1t RPCServercBs8eZddZdZdZdZdZRS(cCs/|dkrt}ntjj|||dS(N(tNonet RPCHandlert SocketServert TCPServert__init__(tselftaddrt handlerclass((s#/usr/lib64/python2.7/idlelib/rpc.pyR Gs  cCsdS(s@Override TCPServer method, no bind() phase for connecting entityN((R ((s#/usr/lib64/python2.7/idlelib/rpc.pyt server_bindLscCs|jj|jdS(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(tsockettconnecttserver_address(R ((s#/usr/lib64/python2.7/idlelib/rpc.pytserver_activatePscCs|j|jfS(s:Override TCPServer method, return already connected socket(RR(R ((s#/usr/lib64/python2.7/idlelib/rpc.pyt get_requestYscCsyWntk rntj}|dddIJ|dIJ|dtjjIJ|dI|IJ|dIt|IJtjd||d IJ|ddIJt j 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__t threadingt currentThreadtgetNametreprt tracebackt print_exctost_exit(R trequesttclient_addressterf((s#/usr/lib64/python2.7/idlelib/rpc.pyt handle_error]s    N(t__name__t __module__RR RRRR&(((s#/usr/lib64/python2.7/idlelib/rpc.pyREs    itSocketIOcBseZdZdddZdZdZdZdZdZ dZ dZ d Z d Z d Zd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZdZ dZ!RS(icCsdtj|_|dk r'||_n||_|dkrEt}n||_i|_i|_ dS(N( RRt sockthreadRt debuggingtsockt objecttabletobjtablet responsestcvars(R R,R.R+((s#/usr/lib64/python2.7/idlelib/rpc.pyR s       cCs/|j}d|_|dk r+|jndS(N(R,Rtclose(R R,((s#/usr/lib64/python2.7/idlelib/rpc.pyR1s   cCstjddS(s!override for specific exit actioniN(R!R"(R ((s#/usr/lib64/python2.7/idlelib/rpc.pytexithookscGsf|js dS|jdttjj}x"|D]}|dt|}q7Wtj|IJdS(Nt (R+tlocationtstrRRRRR(R targststa((s#/usr/lib64/python2.7/idlelib/rpc.pytdebugs  # cCs||j|t j g|j gg\}}}|j j |t }Wn ttfk rtdnX||}qzWdS(Nsputmessage:%d:isCannot pickle:s}|j|}|jd|j|<|j|jq!W|jdS(s+action taken upon link being closed by peerRRjN(RjN( tEOFhookR9R0R{RR/RR|R2(R tkeyR((s#/usr/lib64/python2.7/idlelib/rpc.pyRs      cCsdS(sBClasses using rpc client/server can override to augment EOF actionN((R ((s#/usr/lib64/python2.7/idlelib/rpc.pyRsN("R'R(R}RR R1R2R9R<R>R\R_RaR]R`R^RhRkRrRgRtRsRbRdRRRRRRRRzRR(((s#/usr/lib64/python2.7/idlelib/rpc.pyR)|s>      *               I RMcBseZRS((R'R((((s#/usr/lib64/python2.7/idlelib/rpc.pyRMscCs t|}|t|sB                2c